6 releases
0.2.4 | Jul 24, 2022 |
---|---|
0.2.3 | Jun 4, 2022 |
0.2.2 | Mar 11, 2022 |
0.2.1 | Dec 19, 2021 |
0.1.0 | Dec 16, 2021 |
#1291 in Encoding
4,902 downloads per month
Used in 2 crates
15KB
360 lines
Serde-CS
Serde-CS provides a serialization/deserialization wrapper for comma separated lists.
lib.rs
:
serde-cs
provides a serialization/deserialization wrapper for comma separated lists.
Examples
Serialization
use serde_cs::vec::CS;
type Csu32 = CS<u32>;
let cs: Csu32 = CS(vec![]);
let s = serde_json::to_string(&cs).unwrap();
assert_eq!(s, r#""""#);
let cs: Csu32 = CS(vec![1]);
let s = serde_json::to_string(&cs).unwrap();
assert_eq!(s, r#""1""#);
let cs: Csu32 = CS(vec![1, 2, 3]);
let s = serde_json::to_string(&cs).unwrap();
assert_eq!(s, r#""1,2,3""#);
Deserialization
use serde_cs::vec::CS;
type Csu32 = CS<u32>;
let s = r#""""#;
let CS(cs): Csu32 = serde_json::from_str(s).unwrap();
assert_eq!(cs, vec![0u32; 0]);
let s = r#"",,,,""#;
let CS(cs): Csu32 = serde_json::from_str(s).unwrap();
assert_eq!(cs, vec![0u32; 0]);
let s = r#"",,1,,,,,""#;
let CS(cs): Csu32 = serde_json::from_str(s).unwrap();
assert_eq!(cs, vec![1]);
let s = r#"",,1,,,2,,,,""#;
let CS(cs): Csu32 = serde_json::from_str(s).unwrap();
assert_eq!(cs, vec![1, 2]);
let s = r#"",,1,,,a,,,,""#;
let res: Result<Csu32, _> = serde_json::from_str(s);
assert!(res.is_err());
Dependencies
~100–335KB