Crates.io | nachricht-serde |
lib.rs | nachricht-serde |
version | 0.4.0 |
source | src |
created_at | 2020-12-22 15:07:01.01526 |
updated_at | 2022-03-26 15:57:58.500472 |
description | Serde bindings for nachricht |
homepage | |
repository | https://github.com/yasammez/nachricht |
max_upload_size | |
id | 326032 |
size | 49,948 |
Serde-bindings for the nachricht data interchange format.
[dependencies]
nachricht-serde = "0.4.0"
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();