nachricht-serde

Crates.ionachricht-serde
lib.rsnachricht-serde
version0.4.0
sourcesrc
created_at2020-12-22 15:07:01.01526
updated_at2022-03-26 15:57:58.500472
descriptionSerde bindings for nachricht
homepage
repositoryhttps://github.com/yasammez/nachricht
max_upload_size
id326032
size49,948
Liv Fischer (yasammez)

documentation

https://docs.rs/nachricht-serde

README

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();
Commit count: 52

cargo fmt