Crates.io | hexhex |
lib.rs | hexhex |
version | 1.1.1 |
source | src |
created_at | 2023-05-26 17:32:08.189239 |
updated_at | 2023-09-29 11:53:53.271491 |
description | hexadecimal conversion 🪄 |
homepage | |
repository | https://git.sr.ht/~quf/hexhex |
max_upload_size | |
id | 875198 |
size | 5,669 |
Features:
String
&str
or &[u8]
to a new byte vector&str
or &[u8]
to bytes in a preallocated buffer#![no_std]
support for a subset of the above (if used with no default features)use hexhex::Hex;
let bytes = [0xc0, 0xff, 0xee];
println!("{}", Hex::new(&bytes)); // no allocations, prints "c0ffee"
use hexhex::{Hex, Case};
let bytes = [0xc0, 0xff, 0xee];
println!("{}", Hex::new(&bytes).with_prefix(true).with_case(Case::Upper)); // no allocations, prints "0xC0FFEE"
Hex
implements the Display
trait, so conversion to string is as easy as:
use hexhex::Hex;
let bytes = [0xc0, 0xff, 0xee];
let hex = Hex::new(&bytes).to_string();
assert_eq!(hex, "c0ffee");
Allocating, only with std
:
use hexhex::decode;
assert_eq!(&decode("c0ffee").unwrap(), &[0xc0, 0xff, 0xee]);
use hexhex::hex_literal;
let bytes: &[u8; 3] = hex_literal!("0xc0ffee");
assert_eq!(bytes, &[0xc0, 0xff, 0xee]);
Licensed under the EUPL-1.2-or-later
Bug reports are very much appreciated. Feel free to request features, but no promises. I do not intend to accept third-party patches at this time.