pub struct TraitMap { /* private fields */ }Expand description
A map of traits keyed by their Shape ID.
This provides efficient lookup of traits during serialization and deserialization.
§Cross-lifetime lookup
Internal storage is keyed by ShapeId<'static> because traits come from
codegen-emitted schemas (themselves 'static). The public get and
contains accessors accept &ShapeId<'_> of any lifetime — runtime-
built shape IDs (e.g. parsed from a wire-format __type field) are
looked up against the 'static-keyed table via ShapeId’s
Borrow<str> impl, which keys on the fully qualified name.
Implementations§
Source§impl TraitMap
impl TraitMap
Sourcepub fn get(&self, id: &ShapeId<'_>) -> Option<&dyn Trait>
pub fn get(&self, id: &ShapeId<'_>) -> Option<&dyn Trait>
Gets a trait by its Shape ID.
Accepts a ShapeId of any lifetime — lookup is by fully
qualified name. A ShapeId<'static> constructed via the
shape_id! macro and a runtime-built ShapeId<'_> with the
same FQN resolve to the same entry.
Sourcepub fn get_fqn(&self, fqn: &str) -> Option<&dyn Trait>
pub fn get_fqn(&self, fqn: &str) -> Option<&dyn Trait>
Looks up a trait by its fully qualified name (e.g.
"smithy.api#sensitive").
Equivalent to Self::get when the caller already has the FQN
as a string slice — for example, after extracting the
__type field from a JSON document.
§Example
use aws_smithy_schema::traits::JsonNameTrait;
use aws_smithy_schema::{shape_id, ShapeId, TraitMap};
let mut traits = TraitMap::new();
traits.insert(Box::new(JsonNameTrait::new("custom_name")));
// Cross-lifetime: a static-lifetime ShapeId from `shape_id!` and a
// runtime-built ShapeId<'_> with the same FQN both resolve via
// `Borrow<str>`. The companion `_fqn` accessor takes `&str` directly.
assert!(traits.get(&shape_id!("smithy.api", "jsonName")).is_some());
assert!(traits.get_fqn("smithy.api#jsonName").is_some());Sourcepub fn contains_fqn(&self, fqn: &str) -> bool
pub fn contains_fqn(&self, fqn: &str) -> bool
Returns true if the map contains a trait with the given fully
qualified name. See Self::get_fqn.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TraitMap
impl !UnwindSafe for TraitMap
impl Freeze for TraitMap
impl Send for TraitMap
impl Sync for TraitMap
impl Unpin for TraitMap
impl UnsafeUnpin for TraitMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more