pub struct Writer<'v>(/* 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; strings are borrowed until
Writer::finish. 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<'v> Writer<'v>
impl<'v> Writer<'v>
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
pub fn str(&mut self, s: &'v str) -> &mut Self
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: &'v str) -> &mut Self
pub fn value(&mut self, v: &'v Value) -> &mut Self
Trait Implementations§
Auto Trait Implementations§
impl<'v> Freeze for Writer<'v>
impl<'v> RefUnwindSafe for Writer<'v>
impl<'v> Send for Writer<'v>
impl<'v> Sync for Writer<'v>
impl<'v> Unpin for Writer<'v>
impl<'v> UnsafeUnpin for Writer<'v>
impl<'v> UnwindSafe for Writer<'v>
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