Function zvariant::to_writer

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

Serialize T to the given writer.

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

Panics

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

Examples

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);