nervosnetwork
faster-hex
Rust

fast hex

Last updated Jun 4, 2026
102
Stars
20
Forks
13
Issues
0
Stars/day
Attention Score
42
Language breakdown
No language data available.
โ–ธ Files click to expand
README

faster-hex

[![License]](#license) [![crate-badge]](https://crates.io/crates/faster-hex)

[crate-badge]: https://img.shields.io/crates/v/faster-hex.svg [license]: https://img.shields.io/badge/License-MIT-green.svg

This program implements hex encoding a slice into a predetermined destination using various different instruction sets.

Benchmark

Running

Runs benchmark
cargo bench

Results

Machine: MacBook Pro (Early 2015) (2.7 GHz Intel Core i5)

Rust: rustc 1.31.0 (abe02cefd 2018-12-04)

Compare with hex:

  • Encoding ~10x over
  • Decoding ~10x over
Compare with rustc-hex:
  • Encoding ~2.5x over
  • Decoding ~7x over

Examples

Encode to hex
use fasterhex::hexstring;

let result = hex_string(b"Hello world!"); assert_eq!(result, "48656c6c6f20776f726c6421");

Encode to upper case hex
use fasterhex::hexstring_upper;

let result = hexstringupper(b"Hello world!"); assert_eq!(result, "48656C6C6F20776F726C6421");

Decode

use fasterhex::hexdecode;

let src = b"48656c6c6f20776f726c6421"; let mut dst = vec![0; src.len() / 2]; hex_decode(src, &mut dst).unwrap(); assert_eq!(dst, b"Hello world!");

Decode with case check
use fasterhex::{hexdecodewithcase, CheckCase};

let src = b"48656c6c6f20776f726c6421"; let mut dst = vec![0; src.len() / 2];

assert!(hexdecodewithcase(src, &mut dst, CheckCase::Lower).isok()); assert_eq!(dst, b"Hello world!");

assert!(hexdecodewithcase(src, &mut dst, CheckCase::None).isok()); assert_eq!(dst, b"Hello world!");

assert!(hexdecodewithcase(src, &mut dst, CheckCase::Upper).iserr());

Serde feature

use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] struct Simple { #[serde(with = "faster_hex")] foo: Vec<u8>, #[serde(with = "fasterhex::nopfxlowercase")] bar: Vec<u8>, }

Notice

Major version zero (0.y.z) is for initial development. Anything MAY change at any time. The public API SHOULD NOT be considered stable.

MINOR version when make incompatible API changes before 1.0.0.

License

This project is licensed under the MIT license.

Third party software

This product includes copies and modifications of software developed by third parties:

stdsimd, licensed under the MIT license or the Apache License (Version 2.0). See the source code files for more details.

Copies of third party licenses can be found in LICENSE-THIRD-PARTY.

๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท nervosnetwork/faster-hex ยท Updated daily from GitHub