Skip to main content

DocumentShapeSerializer

Struct DocumentShapeSerializer 

Source
pub struct DocumentShapeSerializer { /* private fields */ }
Expand description

Builds a [DiscriminatedDocument] from a typed shape via the ShapeSerializer interface.

See the module-level documentation for an overview.

§Discriminator capture

Top-level discriminator capture (e.g. via DiscriminatedDocument::from_struct or via direct calls like ser.write_struct(&MY_SCHEMA, ...)) goes through the inherent DocumentShapeSerializer::write_struct method, which captures the schema’s shape ID into the serializer’s root_discriminator slot.

Nested discriminator capture (a struct member that is itself a struct, called through value.serialize_members(&mut dyn ShapeSerializer)) is not preserved, because [Document] has no per-node discriminator slot — only the outer [DiscriminatedDocument] wrapper carries one. Discriminators apply at the wrapper level, not at every nested struct.

§Example

Use DiscriminatedDocument::from_struct for the common case of converting a SerializableStruct into a [DiscriminatedDocument]:

ⓘ
use aws_smithy_schema::document::DiscriminatedDocumentExt;
use aws_smithy_types::DiscriminatedDocument;

let doc = DiscriminatedDocument::from_struct(MyStruct::SCHEMA, &my_struct)?;

Direct construction is useful when round-tripping pieces of a tree outside the standard entry point:

ⓘ
use aws_smithy_schema::document::DocumentShapeSerializer;
use aws_smithy_schema::serde::ShapeSerializer;

let mut ser = DocumentShapeSerializer::new();
ser.write_string(&aws_smithy_schema::prelude::STRING, "hello")?;
let doc = ser.finish()?;

Implementations§

Source§

impl DocumentShapeSerializer

Source

pub fn new() -> Self

Creates a fresh serializer with an empty frame stack.

Source

pub fn finish(self) -> Result<DiscriminatedDocument, SerdeError>

Consumes the serializer and returns the constructed [DiscriminatedDocument].

The wrapper carries the captured top-level discriminator (the FQN of the schema passed to the inherent DocumentShapeSerializer::write_struct entry point), if any. Settings are not attached — serialize-side documents have no protocol context.

Returns an error if no value has been written yet, if any frame is still open (caller forgot a closing callback), or if the serializer was driven into a malformed state.

Source

pub fn write_struct( &mut self, schema: &Schema<'_>, value: &dyn SerializableStruct, ) -> Result<(), SerdeError>

Inherent struct write that captures the schema’s shape ID as the serializer’s top-level discriminator.

Method resolution prefers this inherent method over the ShapeSerializer::write_struct trait method when the receiver is a concrete &mut DocumentShapeSerializer — so call sites like

ⓘ
let mut ser = DocumentShapeSerializer::new();
ser.write_struct(&MY_SCHEMA, &my_value)?;

hit this method. Indirect calls through &mut dyn ShapeSerializer (e.g., from inside another struct’s serialize_members callback) take the trait method instead, which doesn’t capture a discriminator — nested struct discriminators are deliberately not preserved (see the type-level docs).

Trait Implementations§

Source§

impl Debug for DocumentShapeSerializer

Source§

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

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

impl Default for DocumentShapeSerializer

Source§

fn default() -> DocumentShapeSerializer

Returns the “default value” for a type. Read more
Source§

impl ShapeSerializer for DocumentShapeSerializer

Source§

fn write_struct( &mut self, schema: &Schema<'_>, value: &dyn SerializableStruct, ) -> Result<(), SerdeError>

Writes a structure to the serializer. Read more
Source§

fn write_list( &mut self, schema: &Schema<'_>, write_elements: &dyn Fn(&mut dyn ShapeSerializer) -> Result<(), SerdeError>, ) -> Result<(), SerdeError>

Writes a list to the serializer. Read more
Source§

fn write_map( &mut self, schema: &Schema<'_>, write_entries: &dyn Fn(&mut dyn ShapeSerializer) -> Result<(), SerdeError>, ) -> Result<(), SerdeError>

Writes a map to the serializer. Read more
Source§

fn write_boolean( &mut self, schema: &Schema<'_>, value: bool, ) -> Result<(), SerdeError>

Writes a boolean value.
Source§

fn write_byte( &mut self, schema: &Schema<'_>, value: i8, ) -> Result<(), SerdeError>

Writes a byte (i8) value.
Source§

fn write_short( &mut self, schema: &Schema<'_>, value: i16, ) -> Result<(), SerdeError>

Writes a short (i16) value.
Source§

fn write_integer( &mut self, schema: &Schema<'_>, value: i32, ) -> Result<(), SerdeError>

Writes an integer (i32) value.
Source§

fn write_long( &mut self, schema: &Schema<'_>, value: i64, ) -> Result<(), SerdeError>

Writes a long (i64) value.
Source§

fn write_float( &mut self, schema: &Schema<'_>, value: f32, ) -> Result<(), SerdeError>

Writes a float (f32) value.
Source§

fn write_double( &mut self, schema: &Schema<'_>, value: f64, ) -> Result<(), SerdeError>

Writes a double (f64) value.
Source§

fn write_big_integer( &mut self, schema: &Schema<'_>, value: &BigInteger, ) -> Result<(), SerdeError>

Writes a big integer value.
Source§

fn write_big_decimal( &mut self, schema: &Schema<'_>, value: &BigDecimal, ) -> Result<(), SerdeError>

Writes a big decimal value.
Source§

fn write_string( &mut self, schema: &Schema<'_>, value: &str, ) -> Result<(), SerdeError>

Writes a string value.
Source§

fn write_blob( &mut self, schema: &Schema<'_>, value: Blob, ) -> Result<(), SerdeError>

Writes a blob (byte array) value. Read more
Source§

fn write_timestamp( &mut self, schema: &Schema<'_>, value: &DateTime, ) -> Result<(), SerdeError>

Writes a timestamp value.
Source§

fn write_document( &mut self, schema: &Schema<'_>, value: &Document, ) -> Result<(), SerdeError>

Writes a document value. Read more
Source§

fn write_null(&mut self, schema: &Schema<'_>) -> Result<(), SerdeError>

Writes a null value (for sparse collections).
Source§

fn write_list_with_length( &mut self, schema: &Schema<'_>, length: usize, write_elements: &dyn Fn(&mut dyn ShapeSerializer) -> Result<(), SerdeError>, ) -> Result<(), SerdeError>

Writes a list with a known number of elements, including sparse nulls. Read more
Source§

fn write_map_with_length( &mut self, schema: &Schema<'_>, length: usize, write_entries: &dyn Fn(&mut dyn ShapeSerializer) -> Result<(), SerdeError>, ) -> Result<(), SerdeError>

Writes a map with a known number of entries, including sparse null values. Read more
Source§

fn write_string_list( &mut self, schema: &Schema<'_>, values: &[String], ) -> Result<(), SerdeError>

Writes a list of strings.
Source§

fn write_blob_list( &mut self, schema: &Schema<'_>, values: &[Blob], ) -> Result<(), SerdeError>

Writes a list of blobs.
Source§

fn write_integer_list( &mut self, schema: &Schema<'_>, values: &[i32], ) -> Result<(), SerdeError>

Writes a list of integers.
Source§

fn write_long_list( &mut self, schema: &Schema<'_>, values: &[i64], ) -> Result<(), SerdeError>

Writes a list of longs.
Source§

fn write_string_string_map( &mut self, schema: &Schema<'_>, values: &HashMap<String, String>, ) -> Result<(), SerdeError>

Writes a map with string keys and string values.

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

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

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

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
§

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

§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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