[−][src]Function fixed_width::from_str
pub fn from_str<'de, T>(s: &'de str) -> Result<T, Error> where
T: FixedWidth + Deserialize<'de>,
Deserializes a &str
into the given type that implements FixedWidth
and Deserialize
.
Example
#[macro_use] extern crate serde_derive; extern crate serde; extern crate fixed_width; use fixed_width::{Field, FixedWidth}; #[derive(Deserialize)] struct Record { pub name: String, pub room: usize, } impl FixedWidth for Record { fn fields() -> Vec<Field> { vec![ Field::default().range(0..4), Field::default().range(4..8), ] } } fn main() { let s = "Carl1234"; let record: Record = fixed_width::from_str(&s).unwrap(); assert_eq!(record.name, "Carl"); assert_eq!(record.room, 1234); }