Skip to main content

Read

Trait Read 

Source
pub trait Read<'de> {
Show 26 methods // Required methods fn increment_depth(&mut self) -> Result<()>; fn decrement_depth(&mut self); fn read_nil(&mut self) -> Result<()>; fn read_boolean(&mut self) -> Result<bool>; fn read_u8(&mut self) -> Result<u8>; fn read_u16(&mut self) -> Result<u16>; fn read_u32(&mut self) -> Result<u32>; fn read_u64(&mut self) -> Result<u64>; fn read_i8(&mut self) -> Result<i8>; fn read_i16(&mut self) -> Result<i16>; fn read_i32(&mut self) -> Result<i32>; fn read_i64(&mut self) -> Result<i64>; fn read_f32(&mut self) -> Result<f32>; fn read_f64(&mut self) -> Result<f64>; fn read_timestamp(&mut self) -> Result<(i64, u32)>; fn read_array_len(&mut self) -> Result<usize>; fn read_map_len(&mut self) -> Result<usize>; fn read_ext_len(&mut self) -> Result<(i8, usize)>; fn read_string(&mut self) -> Result<Cow<'de, str>>; fn read_string_bytes(&mut self) -> Result<Cow<'de, [u8]>>; fn read_binary(&mut self) -> Result<Cow<'de, [u8]>>; fn read_option<T: FromMessagePack<'de>>(&mut self) -> Result<Option<T>>; fn read_array<T: FromMessagePack<'de>>(&mut self) -> Result<Vec<T>>; fn read_tag(&mut self) -> Result<Tag<'de>>; // Provided methods fn check_array_len(&mut self, expected: usize) -> Result<()> { ... } fn check_map_len(&mut self, expected: usize) -> Result<()> { ... }
}
Expand description

A trait for reading values from a MessagePack-encoded input.

Required Methods§

Source

fn increment_depth(&mut self) -> Result<()>

Increments the current depth of nested structures.

§Errors

Returns an error if the maximum depth is exceeded.

§Examples
struct Outer {
    inner: Inner,
}

struct Inner {
    value: i32,
}

impl<'de> FromMessagePack<'de> for Outer {
    fn read<R: Read<'de>>(reader: &mut R) -> Result<Self> {
        reader.increment_depth()?;   
        let inner = Inner::read(reader)?;
        reader.decrement_depth();
        Ok(Self { inner })
    }
}

impl<'de> FromMessagePack<'de> for Inner {
    fn read<R: Read<'de>>(reader: &mut R) -> Result<Self> {
        reader.increment_depth()?;
        let value = reader.read_i32()?;
        reader.decrement_depth();
        Ok(Self { value })
    }
}
``
Source

fn decrement_depth(&mut self)

Decrements the current depth of nested structures. This should be called after finishing reading a nested structure.

Source

fn read_nil(&mut self) -> Result<()>

Reads a nil value from the input.

Source

fn read_boolean(&mut self) -> Result<bool>

Reads a boolean value from the input.

Source

fn read_u8(&mut self) -> Result<u8>

Reads an unsigned 8-bit integer from the input.

Source

fn read_u16(&mut self) -> Result<u16>

Reads an unsigned 16-bit integer from the input.

Source

fn read_u32(&mut self) -> Result<u32>

Reads an unsigned 32-bit integer from the input.

Source

fn read_u64(&mut self) -> Result<u64>

Reads an unsigned 64-bit integer from the input.

Source

fn read_i8(&mut self) -> Result<i8>

Reads a signed 8-bit integer from the input.

Source

fn read_i16(&mut self) -> Result<i16>

Reads a signed 16-bit integer from the input.

Source

fn read_i32(&mut self) -> Result<i32>

Reads a signed 32-bit integer from the input.

Source

fn read_i64(&mut self) -> Result<i64>

Reads a signed 64-bit integer from the input.

Source

fn read_f32(&mut self) -> Result<f32>

Reads a 32-bit floating-point number from the input.

Source

fn read_f64(&mut self) -> Result<f64>

Reads a 64-bit floating-point number from the input.

Source

fn read_timestamp(&mut self) -> Result<(i64, u32)>

Reads a timestamp from the input, returning the seconds and nanoseconds components.

Source

fn read_array_len(&mut self) -> Result<usize>

Reads the array header and returns the length of the array.

Source

fn read_map_len(&mut self) -> Result<usize>

Reads the map header and returns the number of key-value pairs in the map.

Source

fn read_ext_len(&mut self) -> Result<(i8, usize)>

Reads the extension header and returns the extension type and length of the data.

Source

fn read_string(&mut self) -> Result<Cow<'de, str>>

Reads a UTF-8 string from the input. Returns a Cow<str> which may borrow from the input data if possible.

Source

fn read_string_bytes(&mut self) -> Result<Cow<'de, [u8]>>

Reads the raw bytes of a string from the input, without validating UTF-8. Returns a Cow<[u8]> which may borrow from the input data if possible.

Source

fn read_binary(&mut self) -> Result<Cow<'de, [u8]>>

Reads the raw bytes of a binary blob from the input. Returns a Cow<[u8]> which may borrow from the input data if possible.

Source

fn read_option<T: FromMessagePack<'de>>(&mut self) -> Result<Option<T>>

Reads an optional value from the input. Returns None if the next value is nil, or Some(value) if it is not.

Source

fn read_array<T: FromMessagePack<'de>>(&mut self) -> Result<Vec<T>>

Reads an array of values from the input, returning a Vec<T>.

Source

fn read_tag(&mut self) -> Result<Tag<'de>>

Reads a tag from the input, which can be either an integer or a string.

Provided Methods§

Source

fn check_array_len(&mut self, expected: usize) -> Result<()>

Validates that the next value in the input is an array of the expected length, and consumes the array header.

Source

fn check_map_len(&mut self, expected: usize) -> Result<()>

Validates that the next value in the input is a map of the expected length, and consumes the map header.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§