from_bytes_with_fields

Function from_bytes_with_fields 

Source
pub fn from_bytes_with_fields<'de, T>(
    bytes: &'de [u8],
    fields: FieldSet,
) -> Result<T, Error>
where T: Deserialize<'de>,
Expand description

Deserializes &[u8] data to the given writer using the provided Fields.

ยงExample

use std::collections::HashMap;
use fixed_width::{FieldSet, from_bytes_with_fields};

let fields = FieldSet::Seq(vec![
    FieldSet::new_field(0..4).name("numbers"),
    FieldSet::new_field(4..8).name("letters"),
]);
let mut bytes = b"1234abcd";

let h: HashMap<String, String> = from_bytes_with_fields(bytes, fields).unwrap();
assert_eq!(h.get("numbers").unwrap(), "1234");
assert_eq!(h.get("letters").unwrap(), "abcd");