Skip to content

Commit

Permalink
docs: add 0x to alloy-primitives readme example (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jan 30, 2025
1 parent 7edc626 commit 3f28b07
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/primitives/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Please consult [the documentation][docs] for more information.
use alloy_primitives::{address, fixed_bytes, Address, FixedBytes, I256, U256};

// FixedBytes
let n: FixedBytes<6> = fixed_bytes!("1234567890ab");
let n: FixedBytes<6> = fixed_bytes!("0x1234567890ab");
assert_eq!(n, "0x1234567890ab".parse::<FixedBytes<6>>().unwrap());
assert_eq!(n.to_string(), "0x1234567890ab");

Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/bits/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub const BLOOM_SIZE_BITS: usize = BLOOM_SIZE_BYTES * 8;
/// Mask, used in accrue
const MASK: usize = BLOOM_SIZE_BITS - 1;
/// Number of bytes per item, used in accrue
const ITEM_BYTES: usize = (BLOOM_SIZE_BITS.ilog2() as usize + 7) / 8;
const ITEM_BYTES: usize = BLOOM_SIZE_BITS.ilog2().div_ceil(8) as usize;

// BLOOM_SIZE_BYTES must be a power of 2
#[allow(clippy::assertions_on_constants)]
Expand Down
14 changes: 7 additions & 7 deletions crates/primitives/src/bits/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,9 @@ mod tests {

#[test]
fn concat_const() {
const A: FixedBytes<2> = fixed_bytes!("0123");
const B: FixedBytes<2> = fixed_bytes!("4567");
const EXPECTED: FixedBytes<4> = fixed_bytes!("01234567");
const A: FixedBytes<2> = fixed_bytes!("0x0123");
const B: FixedBytes<2> = fixed_bytes!("0x4567");
const EXPECTED: FixedBytes<4> = fixed_bytes!("0x01234567");
const ACTUAL: FixedBytes<4> = A.concat_const(B);

assert_eq!(ACTUAL, EXPECTED);
Expand Down Expand Up @@ -666,11 +666,11 @@ mod tests {

#[test]
fn left_padding_from() {
assert_eq!(FixedBytes::<4>::left_padding_from(&[0x01, 0x23]), fixed_bytes!("00000123"));
assert_eq!(FixedBytes::<4>::left_padding_from(&[0x01, 0x23]), fixed_bytes!("0x00000123"));

assert_eq!(
FixedBytes::<4>::left_padding_from(&[0x01, 0x23, 0x45, 0x67]),
fixed_bytes!("01234567")
fixed_bytes!("0x01234567")
);
}

Expand All @@ -682,11 +682,11 @@ mod tests {

#[test]
fn right_padding_from() {
assert_eq!(FixedBytes::<4>::right_padding_from(&[0x01, 0x23]), fixed_bytes!("01230000"));
assert_eq!(FixedBytes::<4>::right_padding_from(&[0x01, 0x23]), fixed_bytes!("0x01230000"));

assert_eq!(
FixedBytes::<4>::right_padding_from(&[0x01, 0x23, 0x45, 0x67]),
fixed_bytes!("01234567")
fixed_bytes!("0x01234567")
);
}

Expand Down
1 change: 1 addition & 0 deletions crates/sol-types/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub const fn words_for(data: &[u8]) -> usize {
/// Calculates the padded length of a slice of a specific length by rounding its
/// length to the next word.
#[inline(always)]
#[allow(clippy::manual_div_ceil)] // `.div_ceil` has worse codegen: https://godbolt.org/z/MenKWfPh9
pub const fn words_for_len(len: usize) -> usize {
(len + 31) / 32
}
Expand Down

0 comments on commit 3f28b07

Please sign in to comment.