Struct jomini::TextDeserializer[][src]

pub struct TextDeserializer;
Expand description

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

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

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

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

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.