[][src]Struct jomini::BinaryDeserializerBuilder

pub struct BinaryDeserializerBuilder { /* fields omitted */ }

Build a tweaked binary deserializer

use jomini::{BinaryDeserializer, BinaryTape, FailedResolveStrategy};
use serde::Deserialize;
use std::collections::HashMap;

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

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

let data = [
   0x82, 0x2d, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x00, 0x45, 0x4e, 0x47,
   0x83, 0x2d, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x00, 0x45, 0x4e, 0x48,
];

let mut map = HashMap::new();
map.insert(0x2d82, String::from("field1"));
map.insert(0x2d83, String::from("field2"));

let mut deserializer = BinaryDeserializer::builder();
deserializer.on_failed_resolve(FailedResolveStrategy::Error);

let tape = BinaryTape::from_slice(&data[..])?;
let b: StructB = deserializer.from_tape(&tape, &map)?;
let c: StructC = deserializer.from_tape(&tape, &map)?;
assert_eq!(b, StructB { field1: "ENG".to_string() });
assert_eq!(c, StructC { field2: "ENH".to_string() });

Implementations

impl BinaryDeserializerBuilder[src]

pub fn new() -> Self[src]

Create a new builder instance

pub fn on_failed_resolve(
    &mut self,
    strategy: FailedResolveStrategy
) -> &mut Self
[src]

Set the behavior when a unknown token is encountered

pub fn from_tape<'a, 'b, 'c, 'res: 'a, RES, T>(
    &'b self,
    tape: &'c BinaryTape<'a>,
    resolver: &'res RES
) -> Result<T, Error> where
    T: Deserialize<'a>,
    RES: TokenResolver
[src]

Deserialize the given binary tape

pub fn from_slice<'a, 'b, 'res: 'a, RES, T>(
    &'b self,
    data: &'a [u8],
    resolver: &'res RES
) -> Result<T, Error> where
    T: Deserialize<'a>,
    RES: TokenResolver
[src]

Convenience method for parsing and deserializing binary data in a single step

Trait Implementations

impl Debug for BinaryDeserializerBuilder[src]

impl Default for BinaryDeserializerBuilder[src]

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.