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 = yog_data::binary::Writer::new();
w.map(2).key("id").str("mymod:ruby").key("count").int(3);
let v = yog_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
pub fn new() -> Self
pub fn null(&mut self) -> &mut Self
pub fn bool(&mut self, b: bool) -> &mut Self
pub fn int(&mut self, n: i64) -> &mut Self
pub fn float(&mut self, f: f64) -> &mut Self
Sourcepub fn float32(&mut self, f: f32) -> &mut Self
pub fn float32(&mut self, f: f32) -> &mut Self
A 32-bit float: half the bytes of Writer::float.
Sourcepub fn floats(&mut self, items: &[f64]) -> &mut Self
pub fn floats(&mut self, items: &[f64]) -> &mut Self
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 Self
pub fn floats32(&mut self, items: &[f32]) -> &mut Self
A list of 32-bit floats, packed: four bytes each, no tag.
pub fn str(&mut self, s: &str) -> &mut Self
Sourcepub fn ints(&mut self, items: impl ExactSizeIterator<Item = i64>) -> &mut Self
pub fn ints(&mut self, items: impl ExactSizeIterator<Item = i64>) -> &mut Self
A list of ints, packed (no tag each).
Sourcepub fn map(&mut self, len: usize) -> &mut Self
pub fn map(&mut self, len: usize) -> &mut Self
A map of len entries, each a Writer::key and a value.
pub fn key(&mut self, k: &str) -> &mut Self
pub fn value(&mut self, v: &Value) -> &mut Self
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