pub struct Deserializer<'de> { /* private fields */ }
Expand description
The struct that handles deserializing VDF into Rust structs
This typically doesn’t need to be invoked directly when from_str()
and
from_str_with_key()
can be used instead
Implementations§
Source§impl<'de> Deserializer<'de>
impl<'de> Deserializer<'de>
Sourcepub fn new_with_key(vdf: Vdf<'de>) -> Result<(Self, Key<'de>)>
pub fn new_with_key(vdf: Vdf<'de>) -> Result<(Self, Key<'de>)>
Attempts to create a new VDF deserializer along with returning the top level VDF key
Sourcepub fn peek_is_value(&mut self) -> bool
pub fn peek_is_value(&mut self) -> bool
Returns if the next token is a value type (str, object, or sequence)
Sourcepub fn next_key_or_str(&mut self) -> Option<Cow<'de, str>>
pub fn next_key_or_str(&mut self) -> Option<Cow<'de, str>>
Returns the next key or str if available
Sourcepub fn next_key_or_str_else_eof(&mut self) -> Result<Cow<'de, str>>
pub fn next_key_or_str_else_eof(&mut self) -> Result<Cow<'de, str>>
Returns the next key or str or returns an appropriate error
Sourcepub fn next_finite_float_else_eof(&mut self) -> Result<f32>
pub fn next_finite_float_else_eof(&mut self) -> Result<f32>
Returns the next finite float or returns an appropriate error
Methods from Deref<Target = Peekable<IntoIter<Token<'de>>>>§
1.0.0 · Sourcepub fn peek(&mut self) -> Option<&<I as Iterator>::Item>
pub fn peek(&mut self) -> Option<&<I as Iterator>::Item>
Returns a reference to the next() value without advancing the iterator.
Like next
, if there is a value, it is wrapped in a Some(T)
.
But if the iteration is over, None
is returned.
Because peek()
returns a reference, and many iterators iterate over
references, there can be a possibly confusing situation where the
return value is a double reference. You can see this effect in the
examples below.
§Examples
Basic usage:
let xs = [1, 2, 3];
let mut iter = xs.iter().peekable();
// peek() lets us see into the future
assert_eq!(iter.peek(), Some(&&1));
assert_eq!(iter.next(), Some(&1));
assert_eq!(iter.next(), Some(&2));
// The iterator does not advance even if we `peek` multiple times
assert_eq!(iter.peek(), Some(&&3));
assert_eq!(iter.peek(), Some(&&3));
assert_eq!(iter.next(), Some(&3));
// After the iterator is finished, so is `peek()`
assert_eq!(iter.peek(), None);
assert_eq!(iter.next(), None);
1.53.0 · Sourcepub fn peek_mut(&mut self) -> Option<&mut <I as Iterator>::Item>
pub fn peek_mut(&mut self) -> Option<&mut <I as Iterator>::Item>
Returns a mutable reference to the next() value without advancing the iterator.
Like next
, if there is a value, it is wrapped in a Some(T)
.
But if the iteration is over, None
is returned.
Because peek_mut()
returns a reference, and many iterators iterate over
references, there can be a possibly confusing situation where the
return value is a double reference. You can see this effect in the examples
below.
§Examples
Basic usage:
let mut iter = [1, 2, 3].iter().peekable();
// Like with `peek()`, we can see into the future without advancing the iterator.
assert_eq!(iter.peek_mut(), Some(&mut &1));
assert_eq!(iter.peek_mut(), Some(&mut &1));
assert_eq!(iter.next(), Some(&1));
// Peek into the iterator and set the value behind the mutable reference.
if let Some(p) = iter.peek_mut() {
assert_eq!(*p, &2);
*p = &5;
}
// The value we put in reappears as the iterator continues.
assert_eq!(iter.collect::<Vec<_>>(), vec![&5, &3]);
1.51.0 · Sourcepub fn next_if(
&mut self,
func: impl FnOnce(&<I as Iterator>::Item) -> bool,
) -> Option<<I as Iterator>::Item>
pub fn next_if( &mut self, func: impl FnOnce(&<I as Iterator>::Item) -> bool, ) -> Option<<I as Iterator>::Item>
Consume and return the next value of this iterator if a condition is true.
If func
returns true
for the next value of this iterator, consume and return it.
Otherwise, return None
.
§Examples
Consume a number if it’s equal to 0.
let mut iter = (0..5).peekable();
// The first item of the iterator is 0; consume it.
assert_eq!(iter.next_if(|&x| x == 0), Some(0));
// The next item returned is now 1, so `next_if` will return `None`.
assert_eq!(iter.next_if(|&x| x == 0), None);
// `next_if` saves the value of the next item if it was not equal to `expected`.
assert_eq!(iter.next(), Some(1));
Consume any number less than 10.
let mut iter = (1..20).peekable();
// Consume all numbers less than 10
while iter.next_if(|&x| x < 10).is_some() {}
// The next value returned will be 10
assert_eq!(iter.next(), Some(10));
1.51.0 · Sourcepub fn next_if_eq<T>(&mut self, expected: &T) -> Option<<I as Iterator>::Item>
pub fn next_if_eq<T>(&mut self, expected: &T) -> Option<<I as Iterator>::Item>
Consume and return the next item if it is equal to expected
.
§Example
Consume a number if it’s equal to 0.
let mut iter = (0..5).peekable();
// The first item of the iterator is 0; consume it.
assert_eq!(iter.next_if_eq(&0), Some(0));
// The next item returned is now 1, so `next_if` will return `None`.
assert_eq!(iter.next_if_eq(&0), None);
// `next_if_eq` saves the value of the next item if it was not equal to `expected`.
assert_eq!(iter.next(), Some(1));
Trait Implementations§
Source§impl<'de> Debug for Deserializer<'de>
impl<'de> Debug for Deserializer<'de>
Source§impl<'de> Deref for Deserializer<'de>
impl<'de> Deref for Deserializer<'de>
Source§impl<'de> DerefMut for Deserializer<'de>
impl<'de> DerefMut for Deserializer<'de>
Source§impl<'de, 'a> Deserializer<'de> for &'a mut Deserializer<'de>
impl<'de, 'a> Deserializer<'de> for &'a mut Deserializer<'de>
Source§type Error = Error
type Error = Error
Source§fn deserialize_any<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_any<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserializer
to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn deserialize_bool<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_bool<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a bool
value.Source§fn deserialize_i8<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_i8<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting an i8
value.Source§fn deserialize_i16<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_i16<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting an i16
value.Source§fn deserialize_i32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_i32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting an i32
value.Source§fn deserialize_i64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_i64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting an i64
value.Source§fn deserialize_u8<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_u8<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a u8
value.Source§fn deserialize_u16<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_u16<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a u16
value.Source§fn deserialize_u32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_u32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a u32
value.Source§fn deserialize_u64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_u64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a u64
value.Source§fn deserialize_f32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_f32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a f32
value.Source§fn deserialize_f64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_f64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a f64
value.Source§fn deserialize_char<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_char<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a char
value.Source§fn deserialize_str<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_str<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_string<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_string<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_bytes<V: Visitor<'de>>(self, _visitor: V) -> Result<V::Value>
fn deserialize_bytes<V: Visitor<'de>>(self, _visitor: V) -> Result<V::Value>
Deserialize
type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_byte_buf<V: Visitor<'de>>(self, _visitor: V) -> Result<V::Value>
fn deserialize_byte_buf<V: Visitor<'de>>(self, _visitor: V) -> Result<V::Value>
Deserialize
type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_option<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_option<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting an optional value. Read moreSource§fn deserialize_unit<V: Visitor<'de>>(self, _visitor: V) -> Result<V::Value>
fn deserialize_unit<V: Visitor<'de>>(self, _visitor: V) -> Result<V::Value>
Deserialize
type is expecting a unit value.Source§fn deserialize_unit_struct<V: Visitor<'de>>(
self,
_name: &'static str,
_visitor: V,
) -> Result<V::Value>
fn deserialize_unit_struct<V: Visitor<'de>>( self, _name: &'static str, _visitor: V, ) -> Result<V::Value>
Deserialize
type is expecting a unit struct with a
particular name.Source§fn deserialize_newtype_struct<V: Visitor<'de>>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value>
fn deserialize_newtype_struct<V: Visitor<'de>>( self, _name: &'static str, visitor: V, ) -> Result<V::Value>
Deserialize
type is expecting a newtype struct with a
particular name.Source§fn deserialize_seq<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_seq<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a sequence of values.Source§fn deserialize_tuple<V: Visitor<'de>>(
self,
len: usize,
visitor: V,
) -> Result<V::Value>
fn deserialize_tuple<V: Visitor<'de>>( self, len: usize, visitor: V, ) -> Result<V::Value>
Deserialize
type is expecting a sequence of values and
knows how many values there are without looking at the serialized data.Source§fn deserialize_tuple_struct<V: Visitor<'de>>(
self,
_name: &'static str,
len: usize,
visitor: V,
) -> Result<V::Value>
fn deserialize_tuple_struct<V: Visitor<'de>>( self, _name: &'static str, len: usize, visitor: V, ) -> Result<V::Value>
Deserialize
type is expecting a tuple struct with a
particular name and number of fields.Source§fn deserialize_map<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_map<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting a map of key-value pairs.Source§fn deserialize_struct<V: Visitor<'de>>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value>
fn deserialize_struct<V: Visitor<'de>>( self, _name: &'static str, _fields: &'static [&'static str], visitor: V, ) -> Result<V::Value>
Deserialize
type is expecting a struct with a particular
name and fields.Source§fn deserialize_enum<V: Visitor<'de>>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value>
fn deserialize_enum<V: Visitor<'de>>( self, _name: &'static str, _variants: &'static [&'static str], visitor: V, ) -> Result<V::Value>
Deserialize
type is expecting an enum value with a
particular name and possible variants.Source§fn deserialize_identifier<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
fn deserialize_identifier<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value>
Deserialize
type is expecting the name of a struct
field or the discriminant of an enum variant.Source§fn deserialize_ignored_any<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value>
fn deserialize_ignored_any<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value>
Deserialize
type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moreSource§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize
implementations should expect to
deserialize their human-readable form. Read more