[][src]Struct jomini::TextDeserializer

pub struct TextDeserializer;

A structure to deserialize text data into Rust values.

By default, if a token is unable to be resolved then it will be ignored by the default. Construct a custom instance through the builder method to tweak this behavior.

The example below demonstrates multiple ways to deserialize data

use jomini::{TextDeserializer, TextTape};
use serde::Deserialize;

#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct StructA {
  #[serde(flatten)]
  b: StructB,

  #[serde(flatten)]
  c: StructC,
}

#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct StructB {
  field1: String,
}

#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct StructC {
  field2: String,
}

let data = b"field1=ENG field2=ENH";

// the data can be parsed and deserialized in one step
let a: StructA = TextDeserializer::from_windows1252_slice(&data[..])?;
assert_eq!(a, StructA {
  b: StructB { field1: "ENG".to_string() },
  c: StructC { field2: "ENH".to_string() },
});

// or split into two steps, whatever is appropriate.
let tape = TextTape::from_slice(&data[..])?;
let b: StructB = TextDeserializer::from_windows1252_tape(&tape)?;
let c: StructC = TextDeserializer::from_windows1252_tape(&tape)?;
assert_eq!(b, StructB { field1: "ENG".to_string() });
assert_eq!(c, StructC { field2: "ENH".to_string() });

Implementations

impl TextDeserializer[src]

pub fn from_windows1252_slice<'a, T>(data: &'a [u8]) -> Result<T, Error> where
    T: Deserialize<'a>, 
[src]

Convenience method for parsing the given text data and deserializing as windows1252 encoded.

pub fn from_windows1252_tape<'b, 'a: 'b, T>(
    tape: &'b TextTape<'a>
) -> Result<T, Error> where
    T: Deserialize<'a>, 
[src]

Deserialize the given text tape assuming quoted strings are windows1252 encoded.

pub fn from_utf8_slice<'a, T>(data: &'a [u8]) -> Result<T, Error> where
    T: Deserialize<'a>, 
[src]

Convenience method for parsing the given text data and deserializing as utf8 encoded.

pub fn from_utf8_tape<'b, 'a: 'b, T>(tape: &'b TextTape<'a>) -> Result<T, Error> where
    T: Deserialize<'a>, 
[src]

Deserialize the given text tape assuming quoted strings are utf8 encoded.

pub fn from_encoded_tape<'b, 'a: 'b, T, E>(
    tape: &'b TextTape<'a>,
    encoding: E
) -> Result<T, Error> where
    T: Deserialize<'a>,
    E: Encoding
[src]

Deserialize the given text tape assuming quoted strings can be decoded according to the given encoder

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.