Function fixed_width::to_string
source · pub fn to_string<T: FixedWidth + Serialize>(record: &T) -> Result<String>
Expand description
Serializes the given type that implements FixedWidth
and Serialize
to a String
.
§Example
use serde_derive::Serialize;
use serde;
use fixed_width::{FieldSet, FixedWidth};
#[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_string(&record).unwrap();
assert_eq!(s, "Carl1234");