Function fixed_width::to_writer_with_fields

source ·
pub fn to_writer_with_fields<'w, T, W>(
    wrtr: &'w mut W,
    val: &T,
    fields: FieldSet
) -> Result<()>
where T: Serialize, W: 'w + Write,
Expand description

Serializes data to the given writer using the provided Fields.

§Example

use fixed_width::{FieldSet, Writer, to_writer_with_fields};

let fields = FieldSet::Seq(vec![
    FieldSet::new_field(0..4),
    FieldSet::new_field(4..8),
]);
let mut w = Writer::from_memory();
let data = vec!["1234", "abcd"];

to_writer_with_fields(&mut w, &data, fields).unwrap();

let s: String = w.into();
assert_eq!("1234abcd", s);