Skip to main content

Trait

Trait Trait 

Source
pub trait Trait:
    Any
    + Send
    + Sync
    + Debug {
    // Required methods
    fn trait_id(&self) -> &ShapeId<'static>;
    fn as_any(&self) -> &dyn Any;
}
Expand description

Trait representing a Smithy trait at runtime.

Traits provide additional metadata about shapes that affect serialization, validation, and other behaviors.

Required Methods§

Source

fn trait_id(&self) -> &ShapeId<'static>

Returns the Shape ID of this trait.

Returns &ShapeId<'static> rather than &ShapeId<'_> because the Any supertrait forces all Trait implementors to be 'static, and Any is required for the Schema::with_traits(LazyLock<TraitMap>) downcast fallback.

The practical consequence: the typed trait wrappers are generic over 'a and so usable on runtime-materialized schemas, but they can only impl Trait for their 'static instantiation. Custom and unknown traits, which reach a schema through the dyn Trait map rather than a typed accessor, therefore remain 'static-only. Lifting that means replacing Any-based downcasting with an explicit tagged representation — a larger change, deliberately out of scope here.

Source

fn as_any(&self) -> &dyn Any

Returns this trait as &dyn Any for downcasting.

Implementors§