Skip to main content

Writer

Struct Writer 

Source
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

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 float32(&mut self, f: f32) -> &mut Self

A 32-bit float: half the bytes of Writer::float.

Source

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.

Source

pub fn floats32(&mut self, items: &[f32]) -> &mut Self

A list of 32-bit floats, packed: four bytes each, no tag.

Source

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

Source

pub fn bytes(&mut self, b: &[u8]) -> &mut Self

Bytes as they are.

Source

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

A list of len values.

Source

pub fn ints(&mut self, items: impl ExactSizeIterator<Item = i64>) -> &mut Self

A list of ints, packed (no tag each).

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: &str) -> &mut Self

Source

pub fn value(&mut self, 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§

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.