[−][src]Struct jomini::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_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_tape(&tape)?; let c: StructC = TextDeserializer::from_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_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
pub fn from_tape<'b, 'a: 'b, T>(tape: &'b TextTape<'a>) -> Result<T, Error> where
T: Deserialize<'a>,
[src]
T: Deserialize<'a>,
Deserialize the given text tape
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,
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.
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>,