#serde #serialization #list #separated #serialization-deserialization

serde-cs

Serde serialization/deserialization for camma separated lists

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

#1285 in Encoding

Download history 1057/week @ 2024-09-02 900/week @ 2024-09-09 963/week @ 2024-09-16 1082/week @ 2024-09-23 1043/week @ 2024-09-30 1150/week @ 2024-10-07 1270/week @ 2024-10-14 1111/week @ 2024-10-21 1318/week @ 2024-10-28 1222/week @ 2024-11-04 1235/week @ 2024-11-11 1371/week @ 2024-11-18 1279/week @ 2024-11-25 1253/week @ 2024-12-02 1194/week @ 2024-12-09 1182/week @ 2024-12-16

5,116 downloads per month
Used in 2 crates

MIT/Apache

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