Skip to content

Commit

Permalink
Merge pull request #31 from korken89/master
Browse files Browse the repository at this point in the history
`const fn`-ify what can be `const` of the API
  • Loading branch information
WaffleLapkin authored Feb 29, 2024
2 parents 77c651c + d44be4b commit 0450dc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const K: usize = 0x517cc1b727220a95;
fn take_first_chunk<'a, const N: usize>(slice: &mut &'a [u8]) -> Option<&'a [u8; N]> {
// TODO: use [T]::split_first_chunk() when stable
if slice.len() < N {
return None
return None;
}

let (first, rest) = slice.split_at(N);
Expand All @@ -94,15 +94,20 @@ fn take_first_chunk<'a, const N: usize>(slice: &mut &'a [u8]) -> Option<&'a [u8;

impl FxHasher {
/// Creates `fx` hasher with a given seed.
pub fn with_seed(seed: usize) -> FxHasher {
pub const fn with_seed(seed: usize) -> FxHasher {
FxHasher { hash: seed }
}

/// Create a default `fq` hasher.
pub const fn default() -> FxHasher {
FxHasher { hash: 0 }
}
}

impl Default for FxHasher {
#[inline]
fn default() -> FxHasher {
FxHasher { hash: 0 }
Self::default()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/seeded_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct FxSeededState {

impl FxSeededState {
/// Constructs a new `FxSeededState` that is initialized with a `seed`.
pub fn with_seed(seed: usize) -> FxSeededState {
pub const fn with_seed(seed: usize) -> FxSeededState {
Self { seed }
}
}
Expand Down

0 comments on commit 0450dc7

Please sign in to comment.