pub struct Stream<T> { /* private fields */ }Expand description
A list of T kept written: its body in the binary form, its strings its own.
A stream that was built here (collect, From<Vec<T>>, a
StreamWriter) always reads. A decoded one has had its framing checked
and nothing more, so an item can fail when it is read: see Stream::iter.
Two streams are equal when they have the same count and the same bytes,
not when their items are equal: the same items written by another encoder
(a different but valid spelling of an int, say) are not equal, and a
stream with an unreadable item equals only a copy of itself. Compare
Stream::to_vec to compare items.
Implementations§
Source§impl<T: Schema> Stream<T>
impl<T: Schema> Stream<T>
Sourcepub fn writer() -> StreamWriter<T>
pub fn writer() -> StreamWriter<T>
Writes items one by one (StreamWriter::push).
Sourcepub fn iter(&self) -> Items<'_, T> ⓘ
pub fn iter(&self) -> Items<'_, T> ⓘ
The items, each read as it’s asked for.
An item that cannot be read (a newer item type, a corrupt byte) is an
Err naming its index and byte, and the iterator ends there; so does
a stream with bytes left after its counted items, with an Err at
index len. iter().collect::<Result<Vec<_>, _>>()
reads them all or stops at the first bad one.
Trait Implementations§
Source§impl<T: Schema> FromIterator<T> for Stream<T>
impl<T: Schema> FromIterator<T> for Stream<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(items: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(items: I) -> Self
Source§impl<'a, T: Schema> IntoIterator for &'a Stream<T>
impl<'a, T: Schema> IntoIterator for &'a Stream<T>
Source§impl<T: Schema> Schema for Stream<T>
impl<T: Schema> Schema for Stream<T>
Source§fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Self>
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Self>
The slow way (a text file, a value): read whole, then written.
Source§fn write(&self) -> Value
fn write(&self) -> Value
The items that read, up to the first that does not: a Value has no
place for an error, so check a decoded stream with Stream::validate.
Source§fn decode(d: &mut Decoder<'_>) -> Option<Self>
fn decode(d: &mut Decoder<'_>) -> Option<Self>
Checks the framing only: the byte length, and that the count fits the
bytes (each item takes one at least, so a hostile count allocates
nothing). The items are read by Stream::iter.
Source§fn pack(&self, p: &mut Packer)
fn pack(&self, p: &mut Packer)
In a frame it’s a list, as its shape says (the items that read, as
in Stream::write).
Source§fn encode(&self, w: &mut Writer)
fn encode(&self, w: &mut Writer)
Schema::write’s
value encoded, unless the type knows better (derived ones do).Source§fn unpack(u: &mut Unpacker<'_>) -> Option<Self>
fn unpack(u: &mut Unpacker<'_>) -> Option<Self>
None if the bytes aren’t what
Schema::pack writes.Source§fn absent() -> Option<Self>
fn absent() -> Option<Self>
None: the field is required.Source§fn write_text(&self, w: &mut Writer)
fn write_text(&self, w: &mut Writer)
crate::text::Writer) —
Schema::write’s value as text, unless the type knows better
(derived ones do): no value tree is built on the way.