serde_bytes_wrapper

Crates.ioserde_bytes_wrapper
lib.rsserde_bytes_wrapper
version0.1.0
sourcesrc
created_at2021-11-03 12:18:29.408596
updated_at2021-11-03 12:18:29.408596
descriptionWrapper for Vec, which uses serde_bytes as representation.
homepagehttps://github.com/dedefer/serde_bytes_wrapper
repositoryhttps://github.com/dedefer/serde_bytes_wrapper
max_upload_size
id476130
size8,453
Danila Fomin (dedefer)

documentation

README

MIT licensed Version Code Coverage Downloads

serde_bytes_wrapper

Wrapper for Vec, which uses serde_bytes as representation.

It implements Deserialize, Serialize and Deref/DerefMut to Vec;

Documentation link

Crates.io link

It is useful when you want something like

#[derive(serde::Deserialize, serde::Serialize, Debug)]
struct Val {
    #[serde(with = "serde_bytes")]
    val: Option<Vec<Vec<u8>>>,
}

you can use instead

use serde_bytes_wrapper::Bytes;

#[derive(serde::Deserialize, serde::Serialize, Debug)]
struct Val {
    val: Option<Vec<Bytes>>,
}

Example

use serde::{Deserialize, Serialize};
use serde_bytes_wrapper::Bytes;

#[derive(Deserialize, Serialize, Debug)]
struct Val {
    val: Option<Vec<Bytes>>,
}

fn main() {
  let result = serde_cbor::to_vec(&Val {
      val: Some(vec![vec![1, 2, 3].into()])
    }).unwrap();
  println!("{:?}", result); // [161, 99, 118, 97, 108, 129, 67, 1, 2, 3]
}
Commit count: 2

cargo fmt