#[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
impl DiscriminatedDocument
Sourcepub fn new(document: Document) -> Self
pub fn new(document: Document) -> Self
Creates a new DiscriminatedDocument wrapping document,
with no discriminator and no settings attached.
Sourcepub fn with_discriminator(self, fqn: impl Into<String>) -> Self
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!.
Sourcepub fn with_settings(self, settings: Arc<dyn DocumentSettings>) -> Self
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.
Sourcepub fn discriminator(&self) -> Option<&str>
pub fn discriminator(&self) -> Option<&str>
Returns the discriminator, if attached.
Sourcepub fn settings(&self) -> Option<&Arc<dyn DocumentSettings>>
pub fn settings(&self) -> Option<&Arc<dyn DocumentSettings>>
Returns a reference to the attached protocol settings, if any.
Sourcepub fn into_document(self) -> Document
pub fn into_document(self) -> Document
Consumes this wrapper and returns the inner document.
Sourcepub fn as_blob(&self) -> Result<Cow<'_, [u8]>, DocumentError>
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:
- With protocol settings attached, delegates to
DocumentSettings::coerce_string_to_blob. - With no settings attached, falls back to the deterministic default: standard base64 decode.
Non-string variants return DocumentError::TypeMismatch.
Sourcepub fn as_timestamp(&self) -> Result<DateTime, DocumentError>
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:
- For
Document::Numberwith settings attached, delegates toDocumentSettings::coerce_number_to_timestamp; with no settings, falls back to the deterministic epoch-seconds default. - For
Document::Stringwith settings attached, delegates toDocumentSettings::coerce_string_to_timestamp; with no settings, falls back to parsing RFC-3339 (date-time), which is Smithy’s default string timestamp format.
Other variants return DocumentError::TypeMismatch.
Trait Implementations§
Source§impl Clone for DiscriminatedDocument
impl Clone for DiscriminatedDocument
Source§fn clone(&self) -> DiscriminatedDocument
fn clone(&self) -> DiscriminatedDocument
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DiscriminatedDocument
impl Debug for DiscriminatedDocument
Source§impl Default for DiscriminatedDocument
impl Default for DiscriminatedDocument
Source§fn default() -> DiscriminatedDocument
fn default() -> DiscriminatedDocument
Source§impl From<Document> for DiscriminatedDocument
impl From<Document> for DiscriminatedDocument
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).
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).
Auto Trait Implementations§
impl Freeze for DiscriminatedDocument
impl !RefUnwindSafe for DiscriminatedDocument
impl Send for DiscriminatedDocument
impl Sync for DiscriminatedDocument
impl Unpin for DiscriminatedDocument
impl UnsafeUnpin for DiscriminatedDocument
impl !UnwindSafe for DiscriminatedDocument
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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