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; passesNowned entry handles to an async closure and returns whatever the closure produces.Entryprobe methods (self) - consume the entry; resolve toOk(Probe::Hit((Claim, T)))when the token matches typeT,Ok(Probe::Miss)if the type doesn’t match, orErr(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 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(orMapAccessOwned) as aDeserializer/DeserializerOwnedwhose only supported probe isdeserialize_map. All other probes returnMiss. Used by enum derives to hand an already-opened map to a variant’sDeserializeimpl. - owned
- probe
- shared_
buf - Shared buffer barrier - zero-alloc, no_std async multi-reader primitive.
- tag_
facade - utils
Macros§
- Detect
Duplicates - Wraps a
MapArmStackto return a duplicate-field error (borrow family). - Detect
Duplicates Owned - Convenience macro to construct a
DetectDuplicatesOwnedwith inferred closure types. - Skip
Unknown - Wraps a
MapArmStackso that unknown map keys are silently consumed (borrow family). - Skip
Unknown Owned - Wraps a
MapArmStackOwnedso that unknown map keys are silently consumed. - TagInjecting
Stack - Wraps a
MapArmStackto intercept a tag field (borrow family). - TagInjecting
Stack Owned - Convenience macro to construct a
TagInjectingStackOwnedwith inferred closure types. - hit
- Propagates
ErrandOk(Probe::Miss)from the enclosing function; unwrapsOk(Probe::Hit(v))tov. - 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_outputsorcrate::MapArmStack::take_outputs. - or_miss
- Unwraps an
Option, returningOk(Probe::Miss)from the enclosing function onNone. - select_
probe
Structs§
- Box
- A pointer type that uniquely owns a heap allocation of type
T. - Flatten
Terminal - 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 nestedStackConcattypes (typically 3+ flatten fields). UseFlattenTerminalBoxedto avoid this. - Flatten
Terminal Boxed - Terminal flatten continuation: calls
map.iterate(SkipUnknownOwned(arms))viaBox::pin. Heap-allocates the future to break the deeply-nested async state-machine chain produced byStackConcat, 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. - Match
Vals - Deserializes a string or byte token, matches it against a list of
(key, value)pairs supplied asExtra, and returns the associated value for the first matching key. - Skip
- Deserializes by discarding the current token unconditionally.
- Unwrap
OrElse - Deserializes
Tnormally onProbe::Hit, or calls a fallback onProbe::Missto produce aTunconditionally. The fallback receives the skipped token’sClaim, so the stream is always advanced exactly once.
Traits§
- Deserialize
Error - Error types that can be constructed by derived
Deserializeimplementations.