pub struct Writer { /* private fields */ }Expand description
Writes the binary form piece by piece, from data that isn’t a Value
— nothing is built or copied on the way. A map or list is given its
length, then that many entries (key then a value) or values.
let mut w = substrate_data::binary::Writer::new();
w.map(2).key("id").str("docs/intro").key("count").int(3);
let v = substrate_data::binary::decode(&w.finish()).unwrap();
assert_eq!(v.get("count").and_then(|c| c.as_i64()), Some(3));Implementations§
Source§impl Writer
impl Writer
Sourcepub fn float(&mut self, f: f64) -> &mut Writer
pub fn float(&mut self, f: f64) -> &mut Writer
A float, eight bytes (Writer::float32 writes four).
Sourcepub fn float32(&mut self, f: f32) -> &mut Writer
pub fn float32(&mut self, f: f32) -> &mut Writer
A 32-bit float: half the bytes of Writer::float.
Sourcepub fn floats(&mut self, items: &[f64]) -> &mut Writer
pub fn floats(&mut self, items: &[f64]) -> &mut Writer
A list of floats, packed, no tag each: four bytes each when every
one is an f32 exactly (tag::FLOATS32), else eight.
Sourcepub fn floats32(&mut self, items: &[f32]) -> &mut Writer
pub fn floats32(&mut self, items: &[f32]) -> &mut Writer
A list of 32-bit floats, packed: four bytes each, no tag.
Sourcepub fn str(&mut self, s: &str) -> &mut Writer
pub fn str(&mut self, s: &str) -> &mut Writer
A string: its bytes the first time, its index after.
Sourcepub fn ints(&mut self, items: impl ExactSizeIterator<Item = i64>) -> &mut Writer
pub fn ints(&mut self, items: impl ExactSizeIterator<Item = i64>) -> &mut Writer
A list of ints, packed (no tag each).
Sourcepub fn map(&mut self, len: usize) -> &mut Writer
pub fn map(&mut self, len: usize) -> &mut Writer
A map of len entries, each a Writer::key and a value.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Writer
impl RefUnwindSafe for Writer
impl Send for Writer
impl Sync for Writer
impl Unpin for Writer
impl UnsafeUnpin for Writer
impl UnwindSafe for Writer
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
Mutably borrows from an owned value. Read more