Crate serde_csv_extra[−][src]
Expand description
Csv-related serde addons
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
struct Foo {
#[serde(with = "serde_csv_extra::vec_num")]
list: Vec<i32>,
#[serde(with = "serde_csv_extra::vec_vec_num")]
matrix: Vec<Vec<i32>>,
#[serde(with = "serde_csv_extra::maybe_image_size")]
image_size: Option<(u8, u16)>,
#[serde(with = "serde_csv_extra::maybe_lat_lon")]
geo: Option<(f32, f32)>,
}
let mut wtr = csv::WriterBuilder::new().has_headers(false).from_writer(Vec::new());
wtr.serialize(
Foo {
list: vec![-1, 1],
matrix: vec![vec![-1, 1], vec![1, -1]],
image_size: Some((16, 1024)),
geo: Some((84.99, -135.00)),
}
).unwrap();
wtr.serialize(
Foo {
list: vec![],
matrix: vec![],
image_size: None,
geo: None,
}
).unwrap();
let s = String::from_utf8(wtr.into_inner().unwrap()).unwrap();
assert_eq!(s, "-1_1,-1_1|1_-1,16x1024,84.99;-135\n,,,\n");
Modules
Some((128, 64))
<–> 128x64
Some((84.99, -135.00))
<–> 84.99;-135.00
&[-1, 1]
<–> -1_1
&[[vec![-1, 1], vec![1, -1]]
<–> -1_1|1_-1