Struct jomini::TextDeserializer [−][src]
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]
T: Deserialize<'a>,
Convenience method for parsing the given text data and deserializing as windows1252 encoded.
pub fn from_windows1252_tape<'a, T>(tape: &TextTape<'a>) -> Result<T, Error> where
T: Deserialize<'a>,
[src]
T: Deserialize<'a>,
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]
T: Deserialize<'a>,
Convenience method for parsing the given text data and deserializing as utf8 encoded.
pub fn from_utf8_tape<'a, 'b, T>(tape: &'b TextTape<'a>) -> Result<T, Error> where
T: Deserialize<'a>,
[src]
T: Deserialize<'a>,
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 + Clone,
[src]
tape: &'b TextTape<'a>,
encoding: E
) -> Result<T, Error> where
T: Deserialize<'a>,
E: Encoding + Clone,
Deserialize the given text tape assuming quoted strings can be decoded according to the given encoder
Auto Trait Implementations
impl RefUnwindSafe for TextDeserializer
impl Send for TextDeserializer
impl Sync for TextDeserializer
impl Unpin for TextDeserializer
impl UnwindSafe for TextDeserializer
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, 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>,