5 releases (3 breaking)
0.4.0 | Mar 26, 2022 |
---|---|
0.3.2 | Dec 28, 2021 |
0.3.1 | Mar 21, 2021 |
0.2.0 | Feb 8, 2021 |
0.1.0 | Dec 22, 2020 |
#1923 in Encoding
91KB
2K
SLoC
nachricht-serde
Serde-bindings for the nachricht data interchange format.
[dependencies]
nachricht-serde = "0.4.0"
Usage example
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub enum Species {
PrionailurusViverrinus,
LynxLynx,
FelisCatus,
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct Cat<'a> {
name: &'a str,
species: Species,
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Message<'a> {
version: u32,
#[serde(borrow)]
cats: Vec<Cat<'a>>,
}
let msg = Message {
version: 1,
cats: vec![
Cat { name: "Jessica", species: Species::PrionailurusViverrinus },
Cat { name: "Wantan", species: Species::LynxLynx },
Cat { name: "Sphinx", species: Species::FelisCatus },
Cat { name: "Chandra", species: Species::PrionailurusViverrinus },
],
};
let bytes = nachricht_serde::to_bytes(&msg).unwrap();
Dependencies
~110–340KB