#serde #hex #encoding #bytes

no-std hex-buffer-serde

Helper for serializing byte buffers as hex strings in serde

6 releases

0.3.0 May 3, 2021
0.2.2 Dec 5, 2020
0.2.1 Mar 15, 2020
0.2.0 Apr 15, 2019
0.1.1 Nov 30, 2018

#286 in Encoding

Download history 654/week @ 2022-01-26 839/week @ 2022-02-02 730/week @ 2022-02-09 1132/week @ 2022-02-16 891/week @ 2022-02-23 790/week @ 2022-03-02 724/week @ 2022-03-09 812/week @ 2022-03-16 1213/week @ 2022-03-23 1159/week @ 2022-03-30 1041/week @ 2022-04-06 853/week @ 2022-04-13 896/week @ 2022-04-20 582/week @ 2022-04-27 993/week @ 2022-05-04 1034/week @ 2022-05-11

3,681 downloads per month
Used in 26 crates (7 directly)


423 lines

Hex encoding helper for serde

Build Status License: Apache-2.0 rust 1.41.0+ required

Documentation: Docs.rs crate docs (master)

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:

hex-buffer-serde = "0.3.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.

Supported Rust Versions

The hex-buffer-serde crate is built against recent stable Rust versions. The minimum of these versions is indicated in the badge at the top of this file. The const_len crate feature requires a newer Rust version (1.51+), but it is disabled by default.

A bump of the minimum supported Rust version will not be considered a semantically breaking change. It is, however, guaranteed that the crate will build on some stable Rust toolchain.


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:

  • You don't need control over the (de)serialized type; it does not need to implement any specific "useful" traits (such as AsRef<[u8]>).
  • Hex encoding is used only with human-readable (de)serializers (e.g., JSON or TOML). If the (de)serializer is not human-readable (e.g., bincode), the type is serialized as a byte array.


hex-buffer-serde is licensed under the Apache License (Version 2.0). See LICENSE for details.