pub trait Write {
Show 18 methods
// Required methods
fn write_nil(&mut self) -> Result<()>;
fn write_boolean(&mut self, b: bool) -> Result<()>;
fn write_u8(&mut self, u: u8) -> Result<()>;
fn write_u16(&mut self, u: u16) -> Result<()>;
fn write_u32(&mut self, u: u32) -> Result<()>;
fn write_u64(&mut self, u: u64) -> Result<()>;
fn write_i8(&mut self, i: i8) -> Result<()>;
fn write_i16(&mut self, i: i16) -> Result<()>;
fn write_i32(&mut self, i: i32) -> Result<()>;
fn write_i64(&mut self, i: i64) -> Result<()>;
fn write_f32(&mut self, f: f32) -> Result<()>;
fn write_f64(&mut self, f: f64) -> Result<()>;
fn write_string(&mut self, s: &str) -> Result<()>;
fn write_binary(&mut self, data: &[u8]) -> Result<()>;
fn write_timestamp(&mut self, seconds: i64, nanoseconds: u32) -> Result<()>;
fn write_array_len(&mut self, len: usize) -> Result<()>;
fn write_map_len(&mut self, len: usize) -> Result<()>;
fn write_ext(&mut self, type_id: i8, data: &[u8]) -> Result<()>;
}Expand description
A trait for writing MessagePack-encoded data.
§Examples
struct Point {
x: i32,
y: i32,
}
impl ToMessagePack for Point {
fn write<W: Write>(&self, writer: &mut W) -> Result<()> {
writer.write_array_len(2)?;
writer.write_i32(self.x)?;
writer.write_i32(self.y)?;
Ok(())
}
}Required Methods§
Sourcefn write_boolean(&mut self, b: bool) -> Result<()>
fn write_boolean(&mut self, b: bool) -> Result<()>
Writes a boolean value.
Sourcefn write_string(&mut self, s: &str) -> Result<()>
fn write_string(&mut self, s: &str) -> Result<()>
Writes a UTF-8 string.
Sourcefn write_binary(&mut self, data: &[u8]) -> Result<()>
fn write_binary(&mut self, data: &[u8]) -> Result<()>
Writes a binary blob.
Sourcefn write_timestamp(&mut self, seconds: i64, nanoseconds: u32) -> Result<()>
fn write_timestamp(&mut self, seconds: i64, nanoseconds: u32) -> Result<()>
Writes a timestamp.
Sourcefn write_array_len(&mut self, len: usize) -> Result<()>
fn write_array_len(&mut self, len: usize) -> Result<()>
Writes the array header with the length.
Sourcefn write_map_len(&mut self, len: usize) -> Result<()>
fn write_map_len(&mut self, len: usize) -> Result<()>
Writes the map header with the length.