Skip to main content

DocumentSettings

Trait DocumentSettings 

Source
pub trait DocumentSettings:
    Debug
    + Send
    + Sync {
    // Required method
    fn protocol_id(&self) -> &str;

    // Provided methods
    fn coerce_string_to_blob(&self, s: &str) -> Result<Vec<u8>, DocumentError> { ... }
    fn coerce_string_to_timestamp(
        &self,
        s: &str,
    ) -> Result<DateTime, DocumentError> { ... }
    fn coerce_number_to_timestamp(
        &self,
        n: &Number,
    ) -> Result<DateTime, DocumentError> { ... }
}
Expand description

Protocol-specific settings used by DiscriminatedDocument’s format-aware accessors.

Implementations live alongside the format-specific codec they apply to. For example, the JSON codec’s JsonDocumentSettings will implement this trait to base64-decode strings into blobs and to parse timestamps according to the protocol’s configured @timestampFormat default. A protocol whose wire format already represents blobs and timestamps natively (CBOR, Sparrowhawk) need only implement Self::protocol_id and let every coercion fall through to the default UnsupportedOperation body.

All implementations are required to be Debug + Send + Sync so DiscriminatedDocument can be cloned freely and shared across threads.

Required Methods§

Source

fn protocol_id(&self) -> &str

The Smithy fully-qualified shape ID of the protocol that produced this document, e.g. "aws.protocols#restJson1".

Returned as a string rather than a typed ShapeId: ShapeId lives in aws-smithy-schema, which aws-smithy-types cannot depend on (the dependency direction is fixed). The FQN string is what implementations need anyway — diagnostics, error messages, future protocol-swap dispatch.

Provided Methods§

Source

fn coerce_string_to_blob(&self, s: &str) -> Result<Vec<u8>, DocumentError>

Coerces a string value to a blob.

JSON-style protocols transmit blobs as base64-encoded strings and override this method to decode. A protocol whose encoding of a blob differs from standard base64 overrides it to say so; one that cannot represent a blob in a string at all leaves this at the default, which returns DocumentError::UnsupportedOperation.

When no settings are attached at all, DiscriminatedDocument::as_blob falls back to a standard base64 decode rather than calling this method.

Source

fn coerce_string_to_timestamp(&self, s: &str) -> Result<DateTime, DocumentError>

Coerces a string value to a timestamp.

Used by protocols whose configured timestamp format encodes as a string (e.g. http-date, or date-time when it differs from the RFC-3339 default). Protocols that transmit timestamps only as numbers (epoch seconds) leave this at the default.

Source

fn coerce_number_to_timestamp( &self, n: &Number, ) -> Result<DateTime, DocumentError>

Coerces a numeric value to a timestamp.

Used by protocols whose numeric timestamp encoding differs from plain epoch-seconds. Protocols that transmit timestamps only as strings leave this at the default.

Implementors§