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§
Sourcefn increment_depth(&mut self) -> Result<()>
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 })
}
}
``Sourcefn decrement_depth(&mut self)
fn decrement_depth(&mut self)
Decrements the current depth of nested structures. This should be called after finishing reading a nested structure.
Sourcefn read_boolean(&mut self) -> Result<bool>
fn read_boolean(&mut self) -> Result<bool>
Reads a boolean value from the input.
Sourcefn read_timestamp(&mut self) -> Result<(i64, u32)>
fn read_timestamp(&mut self) -> Result<(i64, u32)>
Reads a timestamp from the input, returning the seconds and nanoseconds components.
Sourcefn read_array_len(&mut self) -> Result<usize>
fn read_array_len(&mut self) -> Result<usize>
Reads the array header and returns the length of the array.
Sourcefn read_map_len(&mut self) -> Result<usize>
fn read_map_len(&mut self) -> Result<usize>
Reads the map header and returns the number of key-value pairs in the map.
Sourcefn read_ext_len(&mut self) -> Result<(i8, usize)>
fn read_ext_len(&mut self) -> Result<(i8, usize)>
Reads the extension header and returns the extension type and length of the data.
Sourcefn read_string(&mut self) -> Result<Cow<'de, str>>
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.
Sourcefn read_string_bytes(&mut self) -> Result<Cow<'de, [u8]>>
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.
Sourcefn read_binary(&mut self) -> Result<Cow<'de, [u8]>>
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.
Sourcefn read_option<T: FromMessagePack<'de>>(&mut self) -> Result<Option<T>>
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.
Sourcefn read_array<T: FromMessagePack<'de>>(&mut self) -> Result<Vec<T>>
fn read_array<T: FromMessagePack<'de>>(&mut self) -> Result<Vec<T>>
Reads an array of values from the input, returning a Vec<T>.
Provided Methods§
Sourcefn check_array_len(&mut self, expected: usize) -> Result<()>
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.
Sourcefn check_map_len(&mut self, expected: usize) -> Result<()>
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.