[][src]Struct fixed_width::Deserializer

pub struct Deserializer<'r> { /* fields omitted */ }

A deserialized for fixed width data. Reads from the given bytes using the provided field definitions to determine how many bytes to read for each deserialized value.

Methods

impl<'r, 'de> Deserializer<'r>[src]

pub fn new(input: &'r [u8], fields: Vec<Field>) -> Self[src]

Creates a new Deserializer from the given bytes and field definitions.

Example

extern crate serde;
extern crate fixed_width;

use fixed_width::{Deserializer, Field};
use serde::Deserialize;
use std::collections::HashMap;

fn main() {
    let input = b"1234abcd99";
    let fields = vec![
        Field::default().range(0..4).name(Some("numbers")),
        Field::default().range(4..8).name(Some("letters")),
        Field::default().range(8..10),
    ];

    let mut de = Deserializer::new(input, fields);
    let h: HashMap<String, String> = HashMap::deserialize(&mut de).unwrap();

    assert_eq!(h.get("numbers").unwrap(), "1234");
    assert_eq!(h.get("letters").unwrap(), "abcd");
    // If no name is supplied, the byte range is used as the key instead.
    assert_eq!(h.get("8..10").unwrap(), "99");
}

pub fn get_ref(&self) -> &[u8][src]

Gets a reference to the underlying input bytes.

Example

use fixed_width::{Deserializer, Field, Reader};

let fields = vec![Field::default().range(0..3)];
let de = Deserializer::new(b"foobar", fields);

assert_eq!(de.get_ref(), b"foobar");

Trait Implementations

impl<'a, 'de: 'a> SeqAccess<'de> for &'a mut Deserializer<'de>[src]

type Error = DeserializeError

The error type that can be returned if some error occurs during deserialization. Read more

fn next_element<T>(&mut self) -> Result<Option<T>, Self::Error> where
    T: Deserialize<'de>, 
[src]

This returns Ok(Some(value)) for the next value in the sequence, or Ok(None) if there are no more remaining items. Read more

fn size_hint(&self) -> Option<usize>[src]

Returns the number of elements remaining in the sequence, if known.

impl<'a, 'de: 'a> Deserializer<'de> for &'a mut Deserializer<'de>[src]

type Error = DeserializeError

The error type that can be returned if some error occurs during deserialization. Read more

fn deserialize_i128<V>(
    self,
    visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error> where
    V: Visitor<'de>, 
[src]

Hint that the Deserialize type is expecting an i128 value. Read more

fn deserialize_u128<V>(
    self,
    visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error> where
    V: Visitor<'de>, 
[src]

Hint that the Deserialize type is expecting an u128 value. Read more

fn is_human_readable(&self) -> bool[src]

Determine whether Deserialize implementations should expect to deserialize their human-readable form. Read more

impl<'a, 'de: 'a> MapAccess<'de> for &'a mut Deserializer<'de>[src]

type Error = DeserializeError

The error type that can be returned if some error occurs during deserialization. Read more

fn next_entry_seed<K, V>(
    &mut self,
    kseed: K,
    vseed: V
) -> Result<Option<(<K as DeserializeSeed<'de>>::Value, <V as DeserializeSeed<'de>>::Value)>, Self::Error> where
    K: DeserializeSeed<'de>,
    V: DeserializeSeed<'de>, 
[src]

This returns Ok(Some((key, value))) for the next (key-value) pair in the map, or Ok(None) if there are no more remaining items. Read more

fn next_key<K>(&mut self) -> Result<Option<K>, Self::Error> where
    K: Deserialize<'de>, 
[src]

This returns Ok(Some(key)) for the next key in the map, or Ok(None) if there are no more remaining entries. Read more

fn next_value<V>(&mut self) -> Result<V, Self::Error> where
    V: Deserialize<'de>, 
[src]

This returns a Ok(value) for the next value in the map. Read more

fn next_entry<K, V>(&mut self) -> Result<Option<(K, V)>, Self::Error> where
    K: Deserialize<'de>,
    V: Deserialize<'de>, 
[src]

This returns Ok(Some((key, value))) for the next (key-value) pair in the map, or Ok(None) if there are no more remaining items. Read more

fn size_hint(&self) -> Option<usize>[src]

Returns the number of entries remaining in the map, if known.

impl<'a, 'de: 'a> EnumAccess<'de> for &'a mut Deserializer<'de>[src]

type Error = DeserializeError

The error type that can be returned if some error occurs during deserialization. Read more

type Variant = Self

The Visitor that will be used to deserialize the content of the enum variant. Read more

fn variant<V>(self) -> Result<(V, Self::Variant), Self::Error> where
    V: Deserialize<'de>, 
[src]

variant is called to identify which variant to deserialize. Read more

impl<'a, 'de: 'a> VariantAccess<'de> for &'a mut Deserializer<'de>[src]

type Error = DeserializeError

The error type that can be returned if some error occurs during deserialization. Must match the error type of our EnumAccess. Read more

fn newtype_variant<T>(self) -> Result<T, Self::Error> where
    T: Deserialize<'de>, 
[src]

Called when deserializing a variant with a single value. Read more

Auto Trait Implementations

impl<'r> Send for Deserializer<'r>

impl<'r> Sync for Deserializer<'r>

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.