Skip to main content

Schema

Struct Schema 

Source
pub struct Schema<'a> { /* private fields */ }
Expand description

A Smithy schema — a lightweight runtime representation of a Smithy shape.

Contains the shape’s ID, type, traits relevant to serialization, and references to member schemas (for aggregate types).

Schemas are constructed at compile time (via const) for generated code and prelude types. The Smithy type system is closed, so no extensibility via trait objects is needed.

Implementations§

Source§

impl<'a> Schema<'a>

Source

pub const fn new(id: ShapeId<'a>, shape_type: ShapeType) -> Self

Creates a schema for a simple type (no members).

Source

pub const fn new_struct( id: ShapeId<'a>, shape_type: ShapeType, members: &'a [&'a Schema<'a>], ) -> Self

Creates a schema for a structure or union type.

id and members are borrowed for 'a, so both must outlive the returned schema. For codegen-emitted schemas this is always 'static to 'static. Hand-written runtime construction can use any lifetime — typically the surrounding function body’s:

use aws_smithy_schema::{Schema, ShapeId, ShapeType};

let id = ShapeId::from_parts("ns#Foo", "ns", "Foo");
let member_x = Schema::new_member(
    ShapeId::from_parts("smithy.api#String", "smithy.api", "String"),
    ShapeType::String,
    "x",
    0,
);
let members: [&Schema<'_>; 1] = [&member_x];
let schema = Schema::new_struct(id, ShapeType::Structure, &members);

assert_eq!(schema.shape_id().as_str(), "ns#Foo");
assert_eq!(schema.shape_type(), ShapeType::Structure);

id, member_x, members, and schema all share the surrounding scope’s lifetime; the borrow checker enforces that members[0] outlives schema.

Source

pub const fn new_list(id: ShapeId<'a>, member: &'a Schema<'a>) -> Self

Creates a schema for a list type.

Source

pub const fn new_map( id: ShapeId<'a>, key: &'a Schema<'a>, value: &'a Schema<'a>, ) -> Self

Creates a schema for a map type.

Source

pub const fn new_member( id: ShapeId<'a>, shape_type: ShapeType, member_name: &'a str, member_index: usize, ) -> Self

Creates a member schema wrapping a target schema.

Source

pub fn shape_id(&self) -> &ShapeId<'a>

Returns the Shape ID of this schema.

The returned reference’s outer lifetime is the receiver’s; the inner ShapeId<'a> carries the data’s lifetime, which is 'static for codegen-emitted schemas (preserving the &'static str accessor guarantees that downstream optimizations rely on).

Source

pub fn shape_type(&self) -> ShapeType

Returns the shape type.

Source

pub fn traits(&self) -> Option<&TraitMap>

Returns the fallback trait map for unknown/custom traits.

Source

pub fn sensitive(&self) -> Option<&SensitiveTrait>

Returns the @sensitive trait if present.

Source

pub fn json_name(&self) -> Option<&JsonNameTrait<'a>>

Returns the @jsonName value if present.

Source

pub fn timestamp_format(&self) -> Option<&TimestampFormatTrait>

Returns the @timestampFormat if present.

Source

pub fn xml_name(&self) -> Option<&XmlNameTrait<'a>>

Returns the @xmlName value if present.

Source

pub fn xml_namespace(&self) -> Option<&XmlNamespaceTrait<'a>>

Returns the @xmlNamespace value if present.

Source

pub fn xml_attribute(&self) -> bool

Returns true if this member has the @xmlAttribute trait.

Source

pub fn xml_flattened(&self) -> bool

Returns true if this member has the @xmlFlattened trait.

Source

pub fn xml_unwrapped_output(&self) -> bool

Returns true if this struct’s XML wire format omits the outer wrapper element. See field doc for details.

Source

pub fn streaming(&self) -> bool

Returns true if this shape has the @streaming trait.

In Smithy the trait is applied to a blob or union shape, never to a member, so codegen propagates it from a member’s target into the combined member schema. That makes the distinction available here without model access: a protocol can tell a streaming payload member — whose live body or event receiver is owned elsewhere — from a buffered one it should read itself.

Source

pub fn has_body_members(&self) -> bool

Returns true if this struct has at least one member that serializes to the request/response body, false if every member is HTTP-bound.

Source

pub fn payload_hint(&self) -> PayloadHint

Returns the recorded PayloadHint, or PayloadHint::Unknown if none was recorded.

Callers MUST handle Unknown by deriving the answer themselves; it is the default for every hand-constructed schema and for schemas generated before codegen began recording it.

Source

pub const fn has_http_response_binding(&self) -> bool

Returns true if this member schema has any HTTP response binding trait (@httpHeader, @httpResponseCode, @httpPrefixHeaders, or @httpPayload).

Source

pub fn http_header(&self) -> Option<&HttpHeaderTrait<'a>>

Returns the @httpHeader value if present.

Use HttpHeaderTrait::value_static rather than value() when inserting into Headers, which needs a 'static name; see the field’s comment for why.

Source

pub fn http_query(&self) -> Option<&HttpQueryTrait<'a>>

Returns the @httpQuery value if present.

Source

pub fn http_label(&self) -> Option<&HttpLabelTrait>

Returns the @httpLabel trait if present.

Source

pub fn http_payload(&self) -> Option<&HttpPayloadTrait>

Returns the @httpPayload trait if present.

Source

pub fn http_prefix_headers(&self) -> Option<&HttpPrefixHeadersTrait<'a>>

Returns the @httpPrefixHeaders value if present.

Source

pub fn media_type(&self) -> Option<&MediaTypeTrait<'a>>

Returns the @mediaType trait if present.

Source

pub fn http_query_params(&self) -> Option<&HttpQueryParamsTrait>

Returns the @httpQueryParams trait if present.

Source

pub fn http_response_code(&self) -> Option<&HttpResponseCodeTrait>

Returns the @httpResponseCode trait if present.

Source

pub fn http(&self) -> Option<&HttpTrait<'a>>

Returns the @http trait if present.

This is an operation-level trait included on the input schema for convenience so the protocol serializer can construct the request URI.

Source

pub fn event_header(&self) -> Option<&EventHeaderTrait>

Returns the @eventHeader trait if present.

Source

pub fn event_payload(&self) -> Option<&EventPayloadTrait>

Returns the @eventPayload trait if present.

Source

pub const fn with_original_name(self, name: &'a str) -> Self

Sets the original (pre-synthesis) shape name for synthetic operation input/output shapes. See Schema::original_name for semantics.

Source

pub const fn with_map_members( self, key: &'a Schema<'a>, value: &'a Schema<'a>, ) -> Self

Attaches key and value member schemas to a map member schema. Used by the XML codec to resolve <key> and <value> element names.

Source

pub const fn with_list_member(self, member: &'a Schema<'a>) -> Self

Sets the list member schema on a member schema that targets a list.

Source

pub const fn with_sensitive(self) -> Self

Sets the @sensitive trait.

Source

pub const fn with_json_name(self, value: &'a str) -> Self

Sets the @jsonName trait.

Source

pub const fn with_timestamp_format(self, format: TimestampFormat) -> Self

Sets the @timestampFormat trait.

Source

pub const fn with_xml_name(self, value: &'a str) -> Self

Sets the @xmlName trait.

Source

pub const fn with_xml_attribute(self) -> Self

Sets the @xmlAttribute trait.

Source

pub const fn with_xml_flattened(self) -> Self

Sets the @xmlFlattened trait.

Source

pub const fn with_xml_unwrapped_output(self) -> Self

Marks the struct as an unwrapped XML output. See field doc for details.

Source

pub const fn with_no_body_members(self) -> Self

Marks this struct as having no body members — every member is HTTP-bound. See has_body_members for what this enables.

Source

pub const fn with_payload_hint(self, hint: PayloadHint) -> Self

Records whether an @httpPayload member supplies its own body framing.

Setting this lets the HTTP binding protocol skip a per-request scan of this schema’s members. It is an optimization only: leaving it at PayloadHint::Unknown (the default) produces identical output. See PayloadHint for why.

Source

pub const fn with_http_header(self, value: &'static str) -> Self

Sets the @httpHeader trait.

Takes &'static str, unlike the other wire-format setters, so the binder’s Headers::insert fast path stays allocation-free. A schema built at runtime must supply an interned or leaked header name.

Relaxing this is additive: a with_http_header_borrowed(&'a str) companion can be added without changing this signature or the getter’s.

Source

pub const fn with_http_label(self) -> Self

Sets the @httpLabel trait.

Source

pub const fn with_http_payload(self) -> Self

Sets the @httpPayload trait.

Source

pub const fn with_http_prefix_headers(self, value: &'a str) -> Self

Sets the @httpPrefixHeaders trait.

Source

pub const fn with_http_query(self, value: &'a str) -> Self

Sets the @httpQuery trait.

Source

pub const fn with_http_query_params(self) -> Self

Sets the @httpQueryParams trait.

Source

pub const fn with_http_response_code(self) -> Self

Sets the @httpResponseCode trait.

Source

pub const fn with_http(self, http: HttpTrait<'a>) -> Self

Sets the @http trait (operation-level, included on input schema for convenience).

Source

pub const fn with_streaming(self) -> Self

Sets the @streaming trait.

Source

pub const fn with_event_header(self) -> Self

Sets the @eventHeader trait.

Source

pub const fn with_event_payload(self) -> Self

Sets the @eventPayload trait.

Source

pub const fn with_host_label(self) -> Self

Sets the @hostLabel trait.

Source

pub const fn with_media_type(self, value: &'a str) -> Self

Sets the @mediaType trait.

Source

pub const fn with_xml_namespace( self, uri: &'a str, prefix: Option<&'a str>, ) -> Self

Sets the @xmlNamespace trait.

uri is the namespace URI; prefix optionally declares the xmlns:prefix form. Pass None for the default (unprefixed) xmlns="uri" declaration.

Source

pub const fn with_traits(self, traits: &'a LazyLock<TraitMap>) -> Self

Sets the fallback trait map for unknown/custom traits.

The schema must outlive the LazyLock it references. For codegen-emitted schemas this is always 'static to 'static. Runtime-built schemas must arrange the lifetimes via standard borrow-check discipline.

Source

pub fn extension<T: Send + Sync + 'static>( &self, key: &'static SchemaExtensionKey<T>, ) -> &T

Returns the value of extension key for this schema, computing it on first use.

The value is computed by the key’s provider the first time this schema is asked for it, then cached for the life of the schema. Concurrent first calls compute it once. See the extension module.

§Panics

If called from inside an extension provider for a value that is not yet cached, and if the provider itself panics.

Source

pub fn member_name(&self) -> Option<&'a str>

Returns the member name if this is a member schema.

Returns Option<&'a str> (the schema’s data lifetime, not the receiver’s). For Schema<'static> (codegen-emitted) this is Option<&'static str> and callers can store the name in Cow::Borrowed or other 'static-lifetime contexts without allocating, matching the underlying field type.

Source

pub fn member_index(&self) -> Option<usize>

Returns the member index for member schemas.

This is used internally by generated code for efficient member lookup. Consumer code should not rely on specific position values as they may change.

Source

pub fn original_name(&self) -> Option<&str>

Returns the original (pre-synthesis) shape name for synthetic operation input/output shapes.

None for non-synthetic shapes. See the field documentation for full semantics.

Source

pub fn member_schema(&self, name: &str) -> Option<&Schema<'_>>

Returns the member schema by name (for structures and unions).

Source

pub fn member_schema_by_index(&self, index: usize) -> Option<&Schema<'_>>

Returns the member name and schema by position index (for structures and unions).

This is an optimization for generated code to avoid string lookups. Consumer code should not rely on specific position values as they may change.

Source

pub fn members(&self) -> &[&Schema<'_>]

Returns the member schemas (for structures and unions).

Source

pub fn member(&self) -> Option<&Schema<'_>>

Returns the member schema for collections (list member or map value).

Source

pub fn member_borrowed(&self) -> Option<&'a Schema<'a>>

Like member but returns the 'a (data-lifetime) borrow that codegen actually stores. Use this when the caller must hold a reference to a value/element member schema across nested callbacks without inheriting the parent &self borrow’s lifetime.

For Schema<'static> (codegen-emitted) this returns Option<&'static Schema<'static>>.

Source

pub fn key(&self) -> Option<&Schema<'_>>

Returns the key schema for maps.

Source

pub fn key_borrowed(&self) -> Option<&'a Schema<'a>>

Like key but returns the 'a (data-lifetime) borrow that codegen stores. See member_borrowed.

Source

pub fn is_member(&self) -> bool

Returns true if this is a member schema.

Source

pub fn is_structure(&self) -> bool

Returns true if this is a structure schema.

Source

pub fn is_union(&self) -> bool

Returns true if this is a union schema.

Source

pub fn is_list(&self) -> bool

Returns true if this is a list schema.

Source

pub fn is_map(&self) -> bool

Returns true if this is a map schema.

Source

pub fn is_blob(&self) -> bool

Returns true if this is a blob schema.

Source

pub fn is_string(&self) -> bool

Returns true if this is a string schema.

Trait Implementations§

Source§

impl<'a> Debug for Schema<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for Schema<'a>

§

impl<'a> !RefUnwindSafe for Schema<'a>

§

impl<'a> !UnwindSafe for Schema<'a>

§

impl<'a> Send for Schema<'a>

§

impl<'a> Sync for Schema<'a>

§

impl<'a> Unpin for Schema<'a>

§

impl<'a> UnsafeUnpin for Schema<'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> 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, 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