Skip to main content

DiscriminatedDocument

Struct DiscriminatedDocument 

Source
#[non_exhaustive]
pub struct DiscriminatedDocument { /* private fields */ }
Expand description

A Document together with an optional discriminator and optional protocol settings.

See the module-level documentation for the rationale behind splitting this off Document.

This type is #[non_exhaustive] so that future fields (e.g. a typed Schema reference, if the schema crate ever adds schema-binding to this wrapper) can land additively.

Note that this is deliberately unlike Document, which is intentionally not #[non_exhaustive]: Document is a released, exhaustively-matchable enum, and callers are expected to match it without a wildcard arm. Adding a variant to Document would be a breaking change, which is precisely why the extra context this wrapper carries lives here instead of on Document itself.

Implementations§

Source§

impl DiscriminatedDocument

Source

pub fn new(document: Document) -> Self

Creates a new DiscriminatedDocument wrapping document, with no discriminator and no settings attached.

Source

pub fn with_discriminator(self, fqn: impl Into<String>) -> Self

Attaches a discriminator (a Smithy fully-qualified shape ID) to this document.

Used by the schema-serde pipeline when constructing a document from a typed shape: the schema’s shape_id (in its namespace#name FQN form) gets attached as the discriminator so downstream consumers (the type registry, the __type write path) know what shape the document represents.

The discriminator MUST be an absolute shape ID — the namespace#name FQN form, never a bare shape name. The SEP requires a serialized __type to always be absolute so the document stays context-free for downstream readers, and the type registry keys on the FQN. Passing a relative id is a caller error and trips a debug_assert!.

Source

pub fn with_settings(self, settings: Arc<dyn DocumentSettings>) -> Self

Attaches protocol settings to this document.

Used by codec deserializers to plumb format-specific coercion rules through to downstream consumers of the document tree. The same Arc is cloned into nested documents so the entire tree shares one settings instance.

Source

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

Returns the discriminator, if attached.

Source

pub fn settings(&self) -> Option<&Arc<dyn DocumentSettings>>

Returns a reference to the attached protocol settings, if any.

Source

pub fn document(&self) -> &Document

Returns a reference to the wrapped document data.

Source

pub fn into_document(self) -> Document

Consumes this wrapper and returns the inner document.

Source

pub fn as_blob(&self) -> Result<Cow<'_, [u8]>, DocumentError>

Returns this document’s value as bytes.

Document has no native blob variant: the schema-driven legacy representation of a Smithy blob is a base64-encoded Document::String. This accessor therefore dispatches two ways:

Non-string variants return DocumentError::TypeMismatch.

Source

pub fn as_timestamp(&self) -> Result<DateTime, DocumentError>

Returns this document’s value as a timestamp.

Document has no native timestamp variant: the schema-driven legacy representation of a Smithy timestamp is a Document::Number holding epoch seconds. This accessor dispatches four ways:

Other variants return DocumentError::TypeMismatch.

Trait Implementations§

Source§

impl Clone for DiscriminatedDocument

Source§

fn clone(&self) -> DiscriminatedDocument

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DiscriminatedDocument

Source§

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

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

impl Default for DiscriminatedDocument

Source§

fn default() -> DiscriminatedDocument

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

impl From<Document> for DiscriminatedDocument

Source§

fn from(document: Document) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for DiscriminatedDocument

PartialEq is implemented manually to compare document and discriminator only — settings is metadata about how the document was produced (and dyn DocumentSettings doesn’t admit equality anyway).

Two discriminated documents holding the same data with different settings are considered equal: this matches the behavior of the schema-crate type that this design replaces, and matches user intent (“are these the same document?” doesn’t depend on protocol metadata).

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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

§

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