[][src]Function zvariant::to_writer

pub fn to_writer<B, W, T: ?Sized>(
    writer: &mut W,
    ctxt: EncodingContext<B>,
    value: &T
) -> Result<usize> where
    B: ByteOrder,
    W: Write + Seek,
    T: Serialize + Type

Serialize T to the given writer.

This function returns the number of bytes written to the given writer.


This function will panic if the value to serialize contains file descriptors. Use to_writer_fds if you'd want to potentially pass FDs.


use zvariant::{EncodingContext, from_slice, to_writer};

let ctxt = EncodingContext::<byteorder::LE>::new_dbus(0);
let mut cursor = std::io::Cursor::new(vec![]);
to_writer(&mut cursor, ctxt, &42u32).unwrap();
let value: u32 = from_slice(cursor.get_ref(), ctxt).unwrap();
assert_eq!(value, 42);