[−][src]Struct flexbuffers::Reader
Reader
s allow access to data stored in a Flexbuffer.
Each reader represents a single address in the buffer so data is read lazily. Start a reader
by calling get_root
on your flexbuffer &[u8]
.
- The
get_T
methods return aResult<T, Error>
. They return an OK value if and only if the flexbuffer type matchesT
. This is analogous to the behavior of Rust's json library, though with Result instead of Option. - The
as_T
methods will try their best to return to a value of typeT
(by casting or even parsing a string if necessary) but ultimately returnsT::default
if it fails. This behavior is analogous to that of flexbuffers C++.
Implementations
impl<'de> Reader<'de>
[src]
pub fn get_root(buffer: &'de [u8]) -> Result<Self, Error>
[src]
Parses the flexbuffer from the given buffer. Assumes the flexbuffer root is the last byte of the buffer.
pub fn flexbuffer_type(&self) -> FlexBufferType
[src]
Returns the FlexBufferType of this Reader.
pub fn bitwidth(&self) -> BitWidth
[src]
Returns the bitwidth of this Reader.
pub fn length(&self) -> usize
[src]
Returns the length of the Flexbuffer. If the type has no length, or if an error occurs, 0 is returned.
pub fn is_aligned(&self) -> bool
[src]
Returns true if the flexbuffer is aligned to 8 bytes. This guarantees, for valid
flexbuffers, that the data is correctly aligned in memory and slices can be read directly
e.g. with get_f64s
or get_i16s
.
pub fn as_vector(&self) -> VectorReader<'de>
[src]
pub fn as_map(&self) -> MapReader<'de>
[src]
pub fn get_slice<T: ReadLE>(&self) -> Result<&'de [T], Error>
[src]
Directly reads a slice of type T
where T
is one of u8,u16,u32,u64,i8,i16,i32,i64,f32,f64
.
Returns Err if the type, bitwidth, or memory alignment does not match. Since the bitwidth is
dynamic, its better to use a VectorReader unless you know your data and performance is critical.
pub fn get_bool(&self) -> Result<bool, Error>
[src]
pub fn get_key(&self) -> Result<&'de str, Error>
[src]
pub fn get_blob(&self) -> Result<Blob<'de>, Error>
[src]
pub fn as_blob(&self) -> Blob<'de>
[src]
pub fn get_str(&self) -> Result<&'de str, Error>
[src]
pub fn get_map(&self) -> Result<MapReader<'de>, Error>
[src]
pub fn get_u64(&self) -> Result<u64, Error>
[src]
Tries to read a FlexBufferType::UInt. Returns Err if the type is not a UInt or if the address is out of bounds.
pub fn get_i64(&self) -> Result<i64, Error>
[src]
Tries to read a FlexBufferType::Int. Returns Err if the type is not a UInt or if the address is out of bounds.
pub fn get_f64(&self) -> Result<f64, Error>
[src]
Tries to read a FlexBufferType::Float. Returns Err if the type is not a UInt, if the address is out of bounds, or if its a f16 or f8 (not currently supported).
pub fn as_bool(&self) -> bool
[src]
pub fn as_u64(&self) -> u64
[src]
Returns a u64, casting if necessary. For Maps and Vectors, their length is returned. If anything fails, 0 is returned.
pub fn as_u32(&self) -> u32
[src]
pub fn as_u16(&self) -> u16
[src]
pub fn as_u8(&self) -> u8
[src]
pub fn as_i64(&self) -> i64
[src]
Returns an i64, casting if necessary. For Maps and Vectors, their length is returned. If anything fails, 0 is returned.
pub fn as_i32(&self) -> i32
[src]
pub fn as_i16(&self) -> i16
[src]
pub fn as_i8(&self) -> i8
[src]
pub fn as_f64(&self) -> f64
[src]
Returns an f64, casting if necessary. For Maps and Vectors, their length is returned. If anything fails, 0 is returned.
pub fn as_f32(&self) -> f32
[src]
pub fn as_str(&self) -> &'de str
[src]
Returns empty string if you're not trying to read a string.
pub fn get_vector(&self) -> Result<VectorReader<'de>, Error>
[src]
Trait Implementations
impl<'de> Clone for Reader<'de>
[src]
impl<'de> Debug for Reader<'de>
[src]
impl<'de> Default for Reader<'de>
[src]
impl<'de> Deserializer<'de> for Reader<'de>
[src]
type Error = DeserializationError
The error type that can be returned if some error occurs during deserialization. Read more
pub fn is_human_readable(&self) -> bool
[src]
pub fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_ignored_any<V>(
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_identifier<V>(
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_tuple<V>(
self,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
name: &'static str,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_byte_buf<V>(
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
_name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_i128<V>(
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_u128<V>(
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error> where
V: Visitor<'de>,
impl<'de> Display for Reader<'de>
[src]
impl<'de> VariantAccess<'de> for Reader<'de>
[src]
type Error = DeserializationError
The error type that can be returned if some error occurs during
deserialization. Must match the error type of our EnumAccess
. Read more
pub fn unit_variant(self) -> Result<(), Self::Error>
[src]
pub fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Self::Error> where
T: DeserializeSeed<'de>,
[src]
T: DeserializeSeed<'de>,
pub fn tuple_variant<V>(
self,
_len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
_len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
_fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn newtype_variant<T>(self) -> Result<T, Self::Error> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
Auto Trait Implementations
impl<'de> RefUnwindSafe for Reader<'de>
[src]
impl<'de> Send for Reader<'de>
[src]
impl<'de> Sync for Reader<'de>
[src]
impl<'de> Unpin for Reader<'de>
[src]
impl<'de> UnwindSafe for Reader<'de>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,