Skip to main content

Crate strede

Crate strede 

Source
Expand description

strede - async, zero-alloc, pull-based deserialization.

§Core idea

Stream advancement and type probing are separated:

  • Deserializer::entry (self) - the only way to advance the stream; passes N owned entry handles to an async closure and returns whatever the closure produces.
  • Entry probe methods (self) - consume the entry; resolve to Ok(Probe::Hit((Claim, T))) when the token matches type T, Ok(Probe::Miss) if the type doesn’t match, or Err(e) on a fatal format error.

Use N > 1 to obtain multiple handles for the same slot and race them via select_probe!. The winning arm returns Ok(Probe::Hit((claim, value))); the claim is forwarded to entry as proof of consumption, and entry returns the value:

let v = d.entry(|[e1, e2, e3]| async {
    select_probe! {
        async move {
            let (claim, f) = hit!(e1.deserialize_f32().await);
            Ok(Probe::Hit((claim, Value::Float(f))))
        },
        async move {
            let (claim, s) = hit!(e2.deserialize_str().await);
            Ok(Probe::Hit((claim, Value::Str(s))))
        },
        async move {
            let (claim, m) = hit!(e3.deserialize_map().await);
            let (claim, v) = collect_map(m).await?;
            Ok(Probe::Hit((claim, Value::Map(v))))
        },
        @miss => Ok(Probe::Miss),
    }
}).await?;

Schema mismatches (wrong token type for a probe) resolve Ok(Probe::Miss) - they are not errors and do not advance the stream. Pending on a probe future means only “no data available yet.” Fatal format errors (malformed data, I/O failures) resolve Err(e) and propagate through ?.

Re-exports§

pub use probe::Chunk;
pub use probe::Probe;
pub use shared_buf::Buffer;
pub use shared_buf::Handle;
pub use shared_buf::SharedBuf;
pub use borrow::BytesAccess;
pub use borrow::Deserialize;
pub use borrow::Deserializer;
pub use borrow::Entry;
pub use borrow::FlattenCont;
pub use borrow::FlattenDeserializer;
pub use borrow::FlattenEntry;
pub use borrow::FlattenMapAccess;
pub use borrow::MapAccess;
pub use borrow::MapArmStack;
pub use borrow::MapKeyClaim;
pub use borrow::MapKeyProbe;
pub use borrow::MapValueClaim;
pub use borrow::MapValueProbe;
pub use borrow::SeqAccess;
pub use borrow::SeqEntry;
pub use borrow::StrAccess;
pub use owned::ArmState;
pub use owned::BytesAccessOwned;
pub use owned::DeserializeOwned;
pub use owned::DeserializerOwned;
pub use owned::DetectDuplicatesOwned;
pub use owned::EntryOwned;
pub use owned::FlattenContOwned;
pub use owned::FlattenDeserializerOwned;
pub use owned::FlattenEntryOwned;
pub use owned::FlattenMapAccessOwned;
pub use owned::MapAccessOwned;
pub use owned::MapArm;
pub use owned::MapArmBase;
pub use owned::MapArmSlot;
pub use owned::MapArmStackOwned;
pub use owned::MapKeyClaimOwned;
pub use owned::MapKeyProbeOwned;
pub use owned::MapValueClaimOwned;
pub use owned::MapValueProbeOwned;
pub use owned::NextKey;
pub use owned::SeqAccessOwned;
pub use owned::SeqEntryOwned;
pub use owned::StackConcat;
pub use owned::StrAccessOwned;
pub use owned::TagInjectingStackOwned;
pub use owned::VirtualArmSlot;

Modules§

borrow
map_arm
map_facade
Wraps any MapAccess (or MapAccessOwned) as a Deserializer / DeserializerOwned whose only supported probe is deserialize_map. All other probes return Miss. Used by enum derives to hand an already-opened map to a variant’s Deserialize impl.
owned
probe
shared_buf
Shared buffer barrier - zero-alloc, no_std async multi-reader primitive.
tag_facade
utils

Macros§

DetectDuplicates
Wraps a MapArmStack to return a duplicate-field error (borrow family).
DetectDuplicatesOwned
Convenience macro to construct a DetectDuplicatesOwned with inferred closure types.
SkipUnknown
Wraps a MapArmStack so that unknown map keys are silently consumed (borrow family).
SkipUnknownOwned
Wraps a MapArmStackOwned so that unknown map keys are silently consumed.
TagInjectingStack
Wraps a MapArmStack to intercept a tag field (borrow family).
TagInjectingStackOwned
Convenience macro to construct a TagInjectingStackOwned with inferred closure types.
hit
Propagates Err and Ok(Probe::Miss) from the enclosing function; unwraps Ok(Probe::Hit(v)) to v.
map_arms
Build a left-nested arm tuple from a flat list of arm definitions.
map_outputs
Destructure a left-nested output tuple from crate::MapArmStackOwned::take_outputs or crate::MapArmStack::take_outputs.
or_miss
Unwraps an Option, returning Ok(Probe::Miss) from the enclosing function on None.
select_probe

Structs§

Box
A pointer type that uniquely owns a heap allocation of type T.
FlattenTerminal
Terminal flatten continuation: calls map.iterate(SkipUnknownOwned(arms)) directly. Used for the last (or only) flatten field in a struct. Zero-alloc - may stack-overflow with deeply nested StackConcat types (typically 3+ flatten fields). Use FlattenTerminalBoxed to avoid this.
FlattenTerminalBoxed
Terminal flatten continuation: calls map.iterate(SkipUnknownOwned(arms)) via Box::pin. Heap-allocates the future to break the deeply-nested async state-machine chain produced by StackConcat, preventing stack overflow with 3+ flatten fields. Generated when #[strede(flatten(boxed))] is used.
Match
Deserializes a string or byte token and checks it for an exact match against a caller-supplied value passed as Extra.
MatchVals
Deserializes a string or byte token, matches it against a list of (key, value) pairs supplied as Extra, and returns the associated value for the first matching key.
Skip
Deserializes by discarding the current token unconditionally.
UnwrapOrElse
Deserializes T normally on Probe::Hit, or calls a fallback on Probe::Miss to produce a T unconditionally. The fallback receives the skipped token’s Claim, so the stream is always advanced exactly once.

Traits§

DeserializeError
Error types that can be constructed by derived Deserialize implementations.

Derive Macros§

Deserialize
DeserializeOwned