| Crates.io | hex-buffer-serde |
| lib.rs | hex-buffer-serde |
| version | 0.4.0 |
| created_at | 2018-11-27 17:04:59.185275+00 |
| updated_at | 2022-11-01 12:47:28.83754+00 |
| description | Helper for serializing byte buffers as hex strings in `serde` |
| homepage | |
| repository | https://github.com/slowli/hex-buffer-serde |
| max_upload_size | |
| id | 98954 |
| size | 58,275 |
hex-buffer-serde is a helper crate allowing to serialize types,
which logically correspond to a byte buffer, in hex encoding within serde.
Add this to your Crate.toml:
[dependencies]
hex-buffer-serde = "0.4.0"
Basic usage:
use hex_buffer_serde::{Hex as _, HexForm};
use serde_derive::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Example {
// will be serialized as hex string in human-readable formats
// (e.g., JSON or TOML), and as a byte array in binary formats
// (e.g., bincode).
#[serde(with = "HexForm")]
buffer: [u8; 32],
// other fields...
}
See crate docs for more examples of usage.
hex-serde provides similar functionality and is a viable alternative
if you have the control over the type that needs hex-encoding.
This crate differs from hex-serde in the following ways:
AsRef<[u8]>).serde-with also provides hex encoding / decoding functionality with similar
constraints to hex-serde.
hex-buffer-serde is licensed under the Apache License (Version 2.0).
See LICENSE for details.