Skip to main content

ShapeId

Struct ShapeId 

Source
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>

Source

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.

Source

pub const fn namespace(&self) -> &'a str

Returns the namespace portion of the ShapeId.

Lifetime is 'a — see Self::as_str for rationale.

Source

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.

Source

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§

Source§

impl Borrow<str> for ShapeId<'_>

Source§

fn borrow(&self) -> &str

Borrows the fully qualified name. Combined with the FQN-based Hash/Eq impls, this lets HashMap<ShapeId<'static>, V>::get accept &str keys, enabling cross-lifetime lookup against a 'static-keyed table.

Source§

impl<'a> Clone for ShapeId<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ShapeId<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ShapeId<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ShapeId<'_>

Source§

impl Hash for ShapeId<'_>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Hashes the fully qualified name so that hash(id) agrees with hash(id.as_str()) — required for the Borrow<str> impl.

1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ShapeId<'_>

Source§

fn eq(&self, other: &Self) -> bool

Two ShapeIds are equal iff their fully qualified names match. See the type-level docs for why this is sound.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more