| Crates.io | serde_bytes_wrapper |
| lib.rs | serde_bytes_wrapper |
| version | 0.1.0 |
| created_at | 2021-11-03 12:18:29.408596+00 |
| updated_at | 2021-11-03 12:18:29.408596+00 |
| description | Wrapper for Vec |
| homepage | https://github.com/dedefer/serde_bytes_wrapper |
| repository | https://github.com/dedefer/serde_bytes_wrapper |
| max_upload_size | |
| id | 476130 |
| size | 8,453 |
Wrapper for Vec
It implements Deserialize, Serialize and Deref/DerefMut to Vec
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>>,
}
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]
}