pub fn to_bytes<T: FixedWidth + Serialize>(record: &T) -> Result<Vec<u8>>Expand description
Serializes the given type that implements FixedWidth and Serialize to a String.
ยงExample
use serde_derive::Serialize;
use serde;
use fixed_width::{FixedWidth, FieldSet};
#[derive(Serialize)]
struct Record {
pub name: String,
pub room: usize,
}
impl FixedWidth for Record {
fn fields() -> FieldSet {
FieldSet::Seq(vec![
FieldSet::new_field(0..4),
FieldSet::new_field(4..8),
])
}
}
let record = Record { name: "Carl".to_string(), room: 1234 };
let s = fixed_width::to_bytes(&record).unwrap();
assert_eq!(&s, b"Carl1234");