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>
impl<'a> Schema<'a>
Sourcepub const fn new(id: ShapeId<'a>, shape_type: ShapeType) -> Self
pub const fn new(id: ShapeId<'a>, shape_type: ShapeType) -> Self
Creates a schema for a simple type (no members).
Sourcepub const fn new_struct(
id: ShapeId<'a>,
shape_type: ShapeType,
members: &'a [&'a Schema<'a>],
) -> Self
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.
Sourcepub const fn new_list(id: ShapeId<'a>, member: &'a Schema<'a>) -> Self
pub const fn new_list(id: ShapeId<'a>, member: &'a Schema<'a>) -> Self
Creates a schema for a list type.
Sourcepub const fn new_map(
id: ShapeId<'a>,
key: &'a Schema<'a>,
value: &'a Schema<'a>,
) -> Self
pub const fn new_map( id: ShapeId<'a>, key: &'a Schema<'a>, value: &'a Schema<'a>, ) -> Self
Creates a schema for a map type.
Sourcepub const fn new_member(
id: ShapeId<'a>,
shape_type: ShapeType,
member_name: &'a str,
member_index: usize,
) -> Self
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.
Sourcepub fn shape_id(&self) -> &ShapeId<'a>
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).
Sourcepub fn shape_type(&self) -> ShapeType
pub fn shape_type(&self) -> ShapeType
Returns the shape type.
Sourcepub fn traits(&self) -> Option<&TraitMap>
pub fn traits(&self) -> Option<&TraitMap>
Returns the fallback trait map for unknown/custom traits.
Sourcepub fn sensitive(&self) -> Option<&SensitiveTrait>
pub fn sensitive(&self) -> Option<&SensitiveTrait>
Returns the @sensitive trait if present.
Sourcepub fn json_name(&self) -> Option<&JsonNameTrait<'a>>
pub fn json_name(&self) -> Option<&JsonNameTrait<'a>>
Returns the @jsonName value if present.
Sourcepub fn timestamp_format(&self) -> Option<&TimestampFormatTrait>
pub fn timestamp_format(&self) -> Option<&TimestampFormatTrait>
Returns the @timestampFormat if present.
Sourcepub fn xml_name(&self) -> Option<&XmlNameTrait<'a>>
pub fn xml_name(&self) -> Option<&XmlNameTrait<'a>>
Returns the @xmlName value if present.
Sourcepub fn xml_namespace(&self) -> Option<&XmlNamespaceTrait<'a>>
pub fn xml_namespace(&self) -> Option<&XmlNamespaceTrait<'a>>
Returns the @xmlNamespace value if present.
Sourcepub fn xml_attribute(&self) -> bool
pub fn xml_attribute(&self) -> bool
Returns true if this member has the @xmlAttribute trait.
Sourcepub fn xml_flattened(&self) -> bool
pub fn xml_flattened(&self) -> bool
Returns true if this member has the @xmlFlattened trait.
Sourcepub fn xml_unwrapped_output(&self) -> bool
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.
Sourcepub fn streaming(&self) -> bool
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.
Sourcepub fn has_body_members(&self) -> bool
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.
Sourcepub fn payload_hint(&self) -> PayloadHint
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.
Sourcepub const fn has_http_response_binding(&self) -> bool
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).
Sourcepub fn http_header(&self) -> Option<&HttpHeaderTrait<'a>>
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.
Sourcepub fn http_query(&self) -> Option<&HttpQueryTrait<'a>>
pub fn http_query(&self) -> Option<&HttpQueryTrait<'a>>
Returns the @httpQuery value if present.
Sourcepub fn http_label(&self) -> Option<&HttpLabelTrait>
pub fn http_label(&self) -> Option<&HttpLabelTrait>
Returns the @httpLabel trait if present.
Sourcepub fn http_payload(&self) -> Option<&HttpPayloadTrait>
pub fn http_payload(&self) -> Option<&HttpPayloadTrait>
Returns the @httpPayload trait if present.
Sourcepub fn http_prefix_headers(&self) -> Option<&HttpPrefixHeadersTrait<'a>>
pub fn http_prefix_headers(&self) -> Option<&HttpPrefixHeadersTrait<'a>>
Returns the @httpPrefixHeaders value if present.
Sourcepub fn media_type(&self) -> Option<&MediaTypeTrait<'a>>
pub fn media_type(&self) -> Option<&MediaTypeTrait<'a>>
Returns the @mediaType trait if present.
Sourcepub fn http_query_params(&self) -> Option<&HttpQueryParamsTrait>
pub fn http_query_params(&self) -> Option<&HttpQueryParamsTrait>
Returns the @httpQueryParams trait if present.
Sourcepub fn http_response_code(&self) -> Option<&HttpResponseCodeTrait>
pub fn http_response_code(&self) -> Option<&HttpResponseCodeTrait>
Returns the @httpResponseCode trait if present.
Sourcepub fn http(&self) -> Option<&HttpTrait<'a>>
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.
Sourcepub fn event_header(&self) -> Option<&EventHeaderTrait>
pub fn event_header(&self) -> Option<&EventHeaderTrait>
Returns the @eventHeader trait if present.
Sourcepub fn event_payload(&self) -> Option<&EventPayloadTrait>
pub fn event_payload(&self) -> Option<&EventPayloadTrait>
Returns the @eventPayload trait if present.
Sourcepub const fn with_original_name(self, name: &'a str) -> Self
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.
Sourcepub const fn with_map_members(
self,
key: &'a Schema<'a>,
value: &'a Schema<'a>,
) -> Self
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.
Sourcepub const fn with_list_member(self, member: &'a Schema<'a>) -> Self
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.
Sourcepub const fn with_sensitive(self) -> Self
pub const fn with_sensitive(self) -> Self
Sets the @sensitive trait.
Sourcepub const fn with_json_name(self, value: &'a str) -> Self
pub const fn with_json_name(self, value: &'a str) -> Self
Sets the @jsonName trait.
Sourcepub const fn with_timestamp_format(self, format: TimestampFormat) -> Self
pub const fn with_timestamp_format(self, format: TimestampFormat) -> Self
Sets the @timestampFormat trait.
Sourcepub const fn with_xml_name(self, value: &'a str) -> Self
pub const fn with_xml_name(self, value: &'a str) -> Self
Sets the @xmlName trait.
Sourcepub const fn with_xml_attribute(self) -> Self
pub const fn with_xml_attribute(self) -> Self
Sets the @xmlAttribute trait.
Sourcepub const fn with_xml_flattened(self) -> Self
pub const fn with_xml_flattened(self) -> Self
Sets the @xmlFlattened trait.
Sourcepub const fn with_xml_unwrapped_output(self) -> Self
pub const fn with_xml_unwrapped_output(self) -> Self
Marks the struct as an unwrapped XML output. See field doc for details.
Sourcepub const fn with_no_body_members(self) -> Self
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.
Sourcepub const fn with_payload_hint(self, hint: PayloadHint) -> Self
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.
Sourcepub const fn with_http_header(self, value: &'static str) -> Self
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.
Sourcepub const fn with_http_label(self) -> Self
pub const fn with_http_label(self) -> Self
Sets the @httpLabel trait.
Sourcepub const fn with_http_payload(self) -> Self
pub const fn with_http_payload(self) -> Self
Sets the @httpPayload trait.
Sourcepub const fn with_http_prefix_headers(self, value: &'a str) -> Self
pub const fn with_http_prefix_headers(self, value: &'a str) -> Self
Sets the @httpPrefixHeaders trait.
Sourcepub const fn with_http_query(self, value: &'a str) -> Self
pub const fn with_http_query(self, value: &'a str) -> Self
Sets the @httpQuery trait.
Sourcepub const fn with_http_query_params(self) -> Self
pub const fn with_http_query_params(self) -> Self
Sets the @httpQueryParams trait.
Sourcepub const fn with_http_response_code(self) -> Self
pub const fn with_http_response_code(self) -> Self
Sets the @httpResponseCode trait.
Sourcepub const fn with_http(self, http: HttpTrait<'a>) -> Self
pub const fn with_http(self, http: HttpTrait<'a>) -> Self
Sets the @http trait (operation-level, included on input schema for convenience).
Sourcepub const fn with_streaming(self) -> Self
pub const fn with_streaming(self) -> Self
Sets the @streaming trait.
Sourcepub const fn with_event_header(self) -> Self
pub const fn with_event_header(self) -> Self
Sets the @eventHeader trait.
Sourcepub const fn with_event_payload(self) -> Self
pub const fn with_event_payload(self) -> Self
Sets the @eventPayload trait.
Sourcepub const fn with_host_label(self) -> Self
pub const fn with_host_label(self) -> Self
Sets the @hostLabel trait.
Sourcepub const fn with_media_type(self, value: &'a str) -> Self
pub const fn with_media_type(self, value: &'a str) -> Self
Sets the @mediaType trait.
Sourcepub const fn with_xml_namespace(
self,
uri: &'a str,
prefix: Option<&'a str>,
) -> Self
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.
Sourcepub const fn with_traits(self, traits: &'a LazyLock<TraitMap>) -> Self
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.
Sourcepub fn extension<T: Send + Sync + 'static>(
&self,
key: &'static SchemaExtensionKey<T>,
) -> &T
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.
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 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.
Sourcepub fn member_index(&self) -> Option<usize>
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.
Sourcepub fn original_name(&self) -> Option<&str>
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.
Sourcepub fn member_schema(&self, name: &str) -> Option<&Schema<'_>>
pub fn member_schema(&self, name: &str) -> Option<&Schema<'_>>
Returns the member schema by name (for structures and unions).
Sourcepub fn member_schema_by_index(&self, index: usize) -> Option<&Schema<'_>>
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.
Sourcepub fn members(&self) -> &[&Schema<'_>]
pub fn members(&self) -> &[&Schema<'_>]
Returns the member schemas (for structures and unions).
Sourcepub fn member(&self) -> Option<&Schema<'_>>
pub fn member(&self) -> Option<&Schema<'_>>
Returns the member schema for collections (list member or map value).
Sourcepub fn member_borrowed(&self) -> Option<&'a Schema<'a>>
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>>.
Sourcepub fn key_borrowed(&self) -> Option<&'a Schema<'a>>
pub fn key_borrowed(&self) -> Option<&'a Schema<'a>>
Like key but returns the 'a (data-lifetime) borrow
that codegen stores. See member_borrowed.
Sourcepub fn is_structure(&self) -> bool
pub fn is_structure(&self) -> bool
Returns true if this is a structure schema.
Trait Implementations§
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> 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