8 releases (4 breaking)

Uses new Rust 2024

new 0.5.0 Nov 3, 2025
0.4.0 Aug 17, 2025
0.3.0 Aug 14, 2025
0.2.0 Aug 6, 2025
0.1.3 Aug 2, 2025

#524 in Data structures

Download history 290/week @ 2025-07-30 135/week @ 2025-08-06 229/week @ 2025-08-13 45/week @ 2025-08-20 36/week @ 2025-08-27 22/week @ 2025-09-03 208/week @ 2025-09-10 13/week @ 2025-09-17 24/week @ 2025-09-24 18/week @ 2025-10-01 8/week @ 2025-10-08 24/week @ 2025-10-15 52/week @ 2025-10-22

104 downloads per month
Used in splinter-rs

MIT/Apache

62KB
1.5K SLoC

u24

docs.rs   Build Status   crates.io

An unsigned 24-bit integer type for Rust.

Features

  • u32 layout: Same memory footprint as u32 but enforces 24-bit constraint
  • Num traits: Implements all expected numeric traits from std and num
  • No Std: Does not depend on the Rust stdlib

Examples

Basic construction and usage:

use u24::u24;

// Create u24 values using the macro
let zero = u24!(0);
let small = u24!(42);
let large = u24!(0xFFFFFF); // Maximum value

// Convert from bytes
let from_bytes = u24::from_le_bytes([0x34, 0x12, 0xAB]);
assert_eq!(from_bytes.into_u32(), 0x00_AB1234);

// Convert from u32 with bounds checking
let checked = u24::checked_from_u32(0x123456).unwrap();
let too_big = u24::checked_from_u32(0x01_000000); // None

// Arithmetic operations
let sum = u24!(100) + u24!(200);
let product = u24!(16) * u24!(1024);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.1–2MB
~36K SLoC