#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

#1291 in Encoding

Download history 1058/week @ 2024-07-21 979/week @ 2024-07-28 895/week @ 2024-08-04 847/week @ 2024-08-11 816/week @ 2024-08-18 974/week @ 2024-08-25 1034/week @ 2024-09-01 909/week @ 2024-09-08 960/week @ 2024-09-15 1085/week @ 2024-09-22 1031/week @ 2024-09-29 1132/week @ 2024-10-06 1273/week @ 2024-10-13 1076/week @ 2024-10-20 1332/week @ 2024-10-27 1073/week @ 2024-11-03

4,902 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