pub struct ShapeId<'a> { /* private fields */ }Expand description
A Smithy Shape ID, parameterized over the lifetime of its component strings.
ShapeId<'static> is the codegen-emitted form (zero-allocation,
const-constructible via the shape_id! macro). ShapeId<'a> for
shorter 'a is constructible from runtime-parsed bytes — for example,
from a wire-format __type field on a JSON response.
Use the shape_id! macro to construct 'static instances — it
computes the fully qualified name at compile time from the namespace
and shape name, preventing the parts from getting out of sync.
§Examples
use aws_smithy_schema::{shape_id, ShapeId};
const ID: ShapeId<'static> = shape_id!("smithy.api", "String");
assert_eq!(ID.namespace(), "smithy.api");
assert_eq!(ID.shape_name(), "String");
assert_eq!(ID.as_str(), "smithy.api#String");§Variance
ShapeId<'a> is covariant in 'a because every field is of the
form &'a str. This means a ShapeId<'static> (codegen-emitted) is
usable everywhere a ShapeId<'a> is expected, regardless of 'a.
§Equality, hashing, and borrow
Two ShapeIds compare equal when their fully qualified names
(Self::as_str) compare equal. The other fields are determined by
the FQN for any ShapeId constructed via the shape_id! macro or
Self::from_parts with consistent parts, so this is the same
equality you would get from comparing every field.
FQN-based equality lets ShapeId act as Borrow<str>: a
HashMap<ShapeId<'static>, V> can be looked up by &str (or by
any &ShapeId<'_> via Self::as_str) without going through
the 'static-bound storage key. This is what the cross-lifetime
lookup APIs on TypeRegistry and TraitMap rely on.
Implementations§
Source§impl<'a> ShapeId<'a>
impl<'a> ShapeId<'a>
Sourcepub const fn as_str(&self) -> &'a str
pub const fn as_str(&self) -> &'a str
Returns the fully qualified string representation (e.g. "smithy.api#String").
The return type is &'a str (the lifetime of the data, not the
receiver). Calling this on ShapeId<'static> yields &'static str,
preserving the codegen-side 'static accessor guarantee.
Sourcepub const fn namespace(&self) -> &'a str
pub const fn namespace(&self) -> &'a str
Returns the namespace portion of the ShapeId.
Lifetime is 'a — see Self::as_str for rationale.
Sourcepub const fn shape_name(&self) -> &'a str
pub const fn shape_name(&self) -> &'a str
Returns the shape name portion of the ShapeId.
Lifetime is 'a — see Self::as_str for rationale.
Sourcepub fn member_name(&self) -> Option<&'a str>
pub fn member_name(&self) -> Option<&'a str>
Returns the member name if this is a member shape ID.
Lifetime is 'a — see Self::as_str for rationale.
Trait Implementations§
impl Eq for ShapeId<'_>
Auto Trait Implementations§
impl<'a> Freeze for ShapeId<'a>
impl<'a> RefUnwindSafe for ShapeId<'a>
impl<'a> Send for ShapeId<'a>
impl<'a> Sync for ShapeId<'a>
impl<'a> Unpin for ShapeId<'a>
impl<'a> UnsafeUnpin for ShapeId<'a>
impl<'a> UnwindSafe for ShapeId<'a>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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