Skip to content

Commit

Permalink
Release v9.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Jan 3, 2025
1 parent 40c32e4 commit 3388a5f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 127 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v9.1.0
- Use reference instead of value in `Hexify` trait and related serialize functions.

### v9.0.0
- Expose more friendly APIs, `Hexify` and `DeHexify` traits.
- Un-public some tiny functions to encourage using `Hexify` and `DeHexify` traits.
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ license = "Apache-2.0/GPL-3.0"
name = "array-bytes"
readme = "README.md"
repository = "https://github.com/hack-ink/array-bytes"
version = "9.0.0"
version = "9.1.0"

[profile.ci-dev]
incremental = false
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ assert_eq!(
## Benchmark
The following benchmarks were run on a `Apple M4 Max 64GB - macOS 15.2 (24C101)`.

<div align="right"><sub>Sun, Dec 29th, 2024</sub></div>
<div align="right"><sub>Fri, Jan 3rd, 2025</sub></div>

```rs
// Hexify.
array_bytes::Hexify::hexify time: [11.195 µs 11.227 µs 11.264 µs]
const_hex::encode time: [1.0546 µs 1.0823 µs 1.1099 µs]
faster_hex::hex_string time: [12.054 µs 12.103 µs 12.154 µs]
faster_hex::hex_encode_fallback time: [12.170 µs 12.209 µs 12.245 µs]
hex::encode time: [87.014 µs 87.164 µs 87.312 µs]
rustc_hex::to_hex time: [45.022 µs 45.616 µs 46.304 µs]
array_bytes::Hexify::hexify time: [10.978 µs 10.997 µs 11.021 µs]
const_hex::encode time: [941.68 ns 946.55 ns 951.44 ns]
faster_hex::hex_string time: [11.478 µs 11.498 µs 11.519 µs]
faster_hex::hex_encode_fallback time: [11.546 µs 11.563 µs 11.580 µs]
hex::encode time: [85.347 µs 85.524 µs 85.751 µs]
rustc_hex::to_hex time: [46.267 µs 47.009 µs 47.759 µs]
// Dehexify.
array_bytes::Dehexify::dehexify time: [19.601 µs 19.815 µs 20.061 µs]
array_bytes::dehexify_slice_mut time: [20.455 µs 20.471 µs 20.489 µs]
const_hex::decode time: [14.098 µs 14.118 µs 14.137 µs]
faster_hex::hex_decode time: [29.356 µs 29.395 µs 29.435 µs]
faster_hex::hex_decode_unchecked time: [12.089 µs 12.134 µs 12.208 µs]
faster_hex::hex_decode_fallback time: [12.067 µs 12.082 µs 12.098 µs]
hex::decode time: [97.005 µs 98.854 µs 100.65 µs]
hex::decode_to_slice time: [39.262 µs 40.562 µs 42.064 µs]
rustc_hex::from_hex time: [108.91 µs 110.77 µs 112.53 µs]
array_bytes::Dehexify::dehexify time: [19.143 µs 19.156 µs 19.173 µs]
array_bytes::dehexify_slice_mut time: [20.245 µs 20.274 µs 20.307 µs]
const_hex::decode time: [13.861 µs 14.276 µs 14.975 µs]
faster_hex::hex_decode time: [28.499 µs 28.545 µs 28.593 µs]
faster_hex::hex_decode_unchecked time: [11.775 µs 11.799 µs 11.828 µs]
faster_hex::hex_decode_fallback time: [11.818 µs 11.840 µs 11.862 µs]
hex::decode time: [90.870 µs 91.481 µs 92.126 µs]
hex::decode_to_slice time: [32.272 µs 32.553 µs 32.927 µs]
rustc_hex::from_hex time: [106.68 µs 107.45 µs 108.31 µs]
```

To run the benchmarks yourself:
Expand Down
3 changes: 3 additions & 0 deletions src/hex/dehexify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ static HEX2DIGIT: [Option<u8>; 256] = {
///
/// # Examples
/// ```
/// use array_bytes::{Dehexify, Error};
/// use smallvec::SmallVec;
///
/// // Unsigned.
/// assert_eq!(u8::dehexify("34"), Ok(52));
/// assert_eq!(u16::dehexify("208"), Ok(520));
Expand Down
131 changes: 28 additions & 103 deletions src/hex/hexify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ const HEX_CHARS_UPPER: &[u8; 16] = b"0123456789ABCDEF";
/// ```
pub trait Hexify {
/// Hexify `Self`.
fn hexify(self) -> String;
fn hexify(&self) -> String;

/// Hexify `Self` with uppercase.
fn hexify_upper(self) -> String;
fn hexify_upper(&self) -> String;

/// Hexify `Self` with `0x` prefix.
fn hexify_prefixed(self) -> String;
fn hexify_prefixed(&self) -> String;

/// Hexify `Self` with `0x` prefix and uppercase.
fn hexify_prefixed_upper(self) -> String;
fn hexify_prefixed_upper(&self) -> String;
}
macro_rules! hexify_unsigned {
($self:expr, $map:expr) => {{
Expand Down Expand Up @@ -103,40 +103,22 @@ macro_rules! impl_hexify_for_unsigned {
($($t:ty,)+) => {
$(
impl Hexify for $t {
fn hexify(self) -> String {
fn hexify(&self) -> String {
hexify_unsigned!(self, HEX_CHARS)
}

fn hexify_upper(self) -> String {
fn hexify_upper(&self) -> String {
hexify_unsigned!(self, HEX_CHARS_UPPER)
}

fn hexify_prefixed(self) -> String {
fn hexify_prefixed(&self) -> String {
hexify_unsigned_prefixed!(self, HEX_CHARS)
}

fn hexify_prefixed_upper(self) -> String {
fn hexify_prefixed_upper(&self) -> String {
hexify_unsigned_prefixed!(self, HEX_CHARS_UPPER)
}
}

impl Hexify for &$t {
fn hexify(self) -> String {
(*self).hexify()
}

fn hexify_upper(self) -> String {
(*self).hexify_upper()
}

fn hexify_prefixed(self) -> String {
(*self).hexify_prefixed()
}

fn hexify_prefixed_upper(self) -> String {
(*self).hexify_prefixed_upper()
}
}
)+
};
}
Expand Down Expand Up @@ -202,90 +184,33 @@ macro_rules! hexify_prefixed {
unsafe { String::from_utf8_unchecked(hex_bytes.into_vec()) }
}};
}
impl<const N: usize> Hexify for [u8; N] {
fn hexify(self) -> String {
hexify!(self, HEX_CHARS)
}
macro_rules! hexify_bytes_fns {
() => {
fn hexify(&self) -> String {
hexify!(self, HEX_CHARS)
}

fn hexify_upper(self) -> String {
hexify!(self, HEX_CHARS_UPPER)
}
fn hexify_upper(&self) -> String {
hexify!(self, HEX_CHARS_UPPER)
}

fn hexify_prefixed(self) -> String {
hexify_prefixed!(self, HEX_CHARS)
}
fn hexify_prefixed(&self) -> String {
hexify_prefixed!(self, HEX_CHARS)
}

fn hexify_prefixed_upper(self) -> String {
hexify_prefixed!(self, HEX_CHARS_UPPER)
}
fn hexify_prefixed_upper(&self) -> String {
hexify_prefixed!(self, HEX_CHARS_UPPER)
}
};
}
impl<const N: usize> Hexify for &[u8; N] {
fn hexify(self) -> String {
hexify!(self, HEX_CHARS)
}

fn hexify_upper(self) -> String {
hexify!(self, HEX_CHARS_UPPER)
}

fn hexify_prefixed(self) -> String {
hexify_prefixed!(self, HEX_CHARS)
}

fn hexify_prefixed_upper(self) -> String {
hexify_prefixed!(self, HEX_CHARS_UPPER)
}
impl<const N: usize> Hexify for [u8; N] {
hexify_bytes_fns! {}
}
impl Hexify for &[u8] {
fn hexify(self) -> String {
hexify!(self, HEX_CHARS)
}

fn hexify_upper(self) -> String {
hexify!(self, HEX_CHARS_UPPER)
}

fn hexify_prefixed(self) -> String {
hexify_prefixed!(self, HEX_CHARS)
}

fn hexify_prefixed_upper(self) -> String {
hexify_prefixed!(self, HEX_CHARS_UPPER)
}
impl Hexify for [u8] {
hexify_bytes_fns! {}
}
impl Hexify for Vec<u8> {
fn hexify(self) -> String {
hexify!(self, HEX_CHARS)
}

fn hexify_upper(self) -> String {
hexify!(self, HEX_CHARS_UPPER)
}

fn hexify_prefixed(self) -> String {
hexify_prefixed!(self, HEX_CHARS)
}

fn hexify_prefixed_upper(self) -> String {
hexify_prefixed!(self, HEX_CHARS_UPPER)
}
}
impl Hexify for &Vec<u8> {
fn hexify(self) -> String {
hexify!(self, HEX_CHARS)
}

fn hexify_upper(self) -> String {
hexify!(self, HEX_CHARS_UPPER)
}

fn hexify_prefixed(self) -> String {
hexify_prefixed!(self, HEX_CHARS)
}

fn hexify_prefixed_upper(self) -> String {
hexify_prefixed!(self, HEX_CHARS_UPPER)
}
hexify_bytes_fns! {}
}
#[test]
fn hexify_should_work() {
Expand Down
8 changes: 4 additions & 4 deletions src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{prelude::*, Dehexify, Hexify};
/// r#"{"_0":"5","_1":"2","_2":"0","_3":"01030104"}"#
/// );
/// ```
pub fn ser_hexify<S, T>(value: T, serializer: S) -> Result<S::Ok, S::Error>
pub fn ser_hexify<S, T>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: Hexify,
Expand Down Expand Up @@ -60,7 +60,7 @@ where
/// r#"{"_0":"5","_1":"2","_2":"0","_3":"01030104"}"#
/// );
/// ```
pub fn ser_hexify_upper<S, T>(value: T, serializer: S) -> Result<S::Ok, S::Error>
pub fn ser_hexify_upper<S, T>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: Hexify,
Expand Down Expand Up @@ -91,7 +91,7 @@ where
/// r#"{"_0":"0x5","_1":"0x2","_2":"0x0","_3":"0x01030104"}"#
/// );
/// ```
pub fn ser_hexify_prefixed<T, S>(value: T, serializer: S) -> Result<S::Ok, S::Error>
pub fn ser_hexify_prefixed<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
T: Hexify,
S: Serializer,
Expand Down Expand Up @@ -122,7 +122,7 @@ where
/// r#"{"_0":"0x5","_1":"0x2","_2":"0x0","_3":"0x01030104"}"#
/// );
/// ```
pub fn ser_hexify_prefixed_upper<T, S>(value: T, serializer: S) -> Result<S::Ok, S::Error>
pub fn ser_hexify_prefixed_upper<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: Hexify,
Expand Down

0 comments on commit 3388a5f

Please sign in to comment.