Skip to main content

DiscriminatedDocumentExt

Trait DiscriminatedDocumentExt 

Source
pub trait DiscriminatedDocumentExt {
    // Required methods
    fn from_struct(
        schema: &Schema<'_>,
        value: &dyn SerializableStruct,
    ) -> Result<DiscriminatedDocument, SerdeError>;
    fn as_shape<T, F>(&self, deserialize: F) -> Result<T, SerdeError>
       where F: FnOnce(&mut dyn ShapeDeserializer) -> Result<T, SerdeError>;
    fn shape_type(&self) -> ShapeType;
}
Expand description

Schema-aware operations on [DiscriminatedDocument].

Implemented for [DiscriminatedDocument] in aws-smithy-schema because the methods need Schema, SerializableStruct, and the ShapeDeserializer trait — types that live in this crate. See the trait’s documentation for the rationale.

Required Methods§

Source

fn from_struct( schema: &Schema<'_>, value: &dyn SerializableStruct, ) -> Result<DiscriminatedDocument, SerdeError>

Constructs a [DiscriminatedDocument] from any SerializableStruct by driving it through the DocumentShapeSerializer pipeline.

This is the SEP’s Document.of(struct) entry point. The resulting wrapper carries schema.shape_id().as_str() as its discriminator, so a downstream type registry can find the right schema for the reverse conversion.

Settings are not attached — serialize-side documents have no protocol context.

§Errors

Returns SerdeError if the struct’s serialize_members callback fails (rare — typically only on internal invariant violations or invalid map-key writes).

Source

fn as_shape<T, F>(&self, deserialize: F) -> Result<T, SerdeError>
where F: FnOnce(&mut dyn ShapeDeserializer) -> Result<T, SerdeError>,

Reifies this [DiscriminatedDocument] as a typed shape by driving the given deserialize callback through a DocumentShapeDeserializer.

This is the SEP’s Document.asShape(...) entry point. The callback is typically the generated <Type>::deserialize function on a shape’s data carrier or builder.

§Errors

Returns whatever error the deserialize callback returns — typically a SerdeError::TypeMismatch when the document’s shape doesn’t match what the callback expects.

Source

fn shape_type(&self) -> ShapeType

Returns the ShapeType this document would be reported as if converted to a typed shape.

For numeric values, follows the SEP “Reporting Document ambiguous shape types” guidance — picks the narrowest unambiguous container from the precedence Integer → Long → BigInteger → Double → BigDecimal. Byte, IntEnum, Short, and Float are skipped.

Null is reported as ShapeType::Document since Null itself is not a Smithy type variant.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl DiscriminatedDocumentExt for DiscriminatedDocument

Source§

fn from_struct( schema: &Schema<'_>, value: &dyn SerializableStruct, ) -> Result<DiscriminatedDocument, SerdeError>

Source§

fn as_shape<T, F>(&self, deserialize: F) -> Result<T, SerdeError>
where F: FnOnce(&mut dyn ShapeDeserializer) -> Result<T, SerdeError>,

Source§

fn shape_type(&self) -> ShapeType

Implementors§