Skip to main content

Writer

Struct Writer 

Source
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>

Source

pub fn new() -> Self

Source

pub fn null(&mut self) -> &mut Self

Source

pub fn bool(&mut self, b: bool) -> &mut Self

Source

pub fn int(&mut self, n: i64) -> &mut Self

Source

pub fn float(&mut self, f: f64) -> &mut Self

Source

pub fn str(&mut self, s: &'v str) -> &mut Self

Source

pub fn list(&mut self, len: usize) -> &mut Self

A list of len values.

Source

pub fn map(&mut self, len: usize) -> &mut Self

A map of len entries, each a Writer::key and a value.

Source

pub fn key(&mut self, k: &'v str) -> &mut Self

Source

pub fn value(&mut self, v: &'v Value) -> &mut Self

Source

pub fn finish(self) -> Vec<u8> ⓘ

The bytes.

Trait Implementations§

Source§

impl Default for Writer<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.