#hex #codec #policy #conservative #decoding #msrv

no-std hex-conservative

A hex encoding and decoding crate with a conservative MSRV and dependency policy

6 releases

new 0.2.1 May 23, 2024
0.2.0 Feb 27, 2024
0.1.2 May 14, 2024
0.1.1 Jul 19, 2023
0.0.1 Apr 30, 2023

#202 in Encoding

Download history 21298/week @ 2024-02-04 17857/week @ 2024-02-11 25473/week @ 2024-02-18 23806/week @ 2024-02-25 26319/week @ 2024-03-03 40885/week @ 2024-03-10 52678/week @ 2024-03-17 53873/week @ 2024-03-24 70875/week @ 2024-03-31 67019/week @ 2024-04-07 66956/week @ 2024-04-14 64218/week @ 2024-04-21 49424/week @ 2024-04-28 49920/week @ 2024-05-05 58694/week @ 2024-05-12 51525/week @ 2024-05-19

211,869 downloads per month
Used in 622 crates (18 directly)

CC0 license

64KB
1K SLoC

Bitcoin Hexadecimal Library

General purpose hex encoding/decoding library with a conservative MSRV and dependency policy.

Minimum Supported Rust Version (MSRV)

This library should compile with almost any combination of features on Rust 1.56.1, however we reserve the right to use features to guard compiler specific code so --all-features may not work using the MSRV toolchain.

Githooks

To assist devs in catching errors before running CI we provide some githooks. If you do not already have locally configured githooks you can use the ones in this repository by running, in the root directory of the repository:

git config --local core.hooksPath githooks/

Alternatively add symlinks in your .git/hooks directory to any of the githooks we provide.


lib.rs:

Hex encoding and decoding.

General purpose hex encoding/decoding library with a conservative MSRV and dependency policy.

Basic Usage

// In your manifest use the `package` key to improve import ergonomics.
// hex = { package = "hex-conservative", version = "*" }
use hex::prelude::*;

// Decode an arbitrary length hex string into a vector.
let v = Vec::from_hex("deadbeef").expect("valid hex digits");
// Or a known length hex string into a fixed size array.
let a = <[u8; 4]>::from_hex("deadbeef").expect("valid length and valid hex digits");

// We support `LowerHex` and `UpperHex` out of the box for `[u8]` slices.
println!("An array as lower hex: {:x}", a.as_hex());
// And for vecs since `Vec` derefs to byte slice.
println!("A vector as upper hex: {:X}", v.as_hex());

// Allocate a new string (also `to_upper_hex_string`).
let s = v.to_lower_hex_string();

// Please note, mixed case strings will still parse successfully but we only
// support displaying hex in a single case.
assert_eq!(
    Vec::from_hex("dEaDbEeF").expect("valid mixed case hex digits"),
    Vec::from_hex("deadbeef").expect("valid hex digits"),
);

Dependencies

~61–320KB