Crates.io | serde-csv-extra |
lib.rs | serde-csv-extra |
version | 0.2.0 |
source | src |
created_at | 2021-12-29 15:46:41.587019 |
updated_at | 2021-12-30 12:34:06.862176 |
description | Csv-related serde addons |
homepage | |
repository | https://github.com/imbolc/serde-csv-extra |
max_upload_size | |
id | 504876 |
size | 14,577 |
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");
We appreciate all kinds of contributions, thank you!
The README.md
file isn't meant to be changed directly. It instead generated from the crate's docs
by the cargo-readme command:
cargo install cargo-readme
src/lib.rs
, or wrapping text in README.tpl
cargo readme > README.md
If you have rusty-hook installed the changes will apply automatically on commit.
This project is licensed under the MIT license.