Skip to content

Commit

Permalink
time: use array::from_fn instead of manually creating array (#7000)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde authored Dec 1, 2024
1 parent 38151f3 commit bce9780
Showing 1 changed file with 1 addition and 77 deletions.
78 changes: 1 addition & 77 deletions tokio-util/src/time/wheel/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,86 +39,10 @@ const LEVEL_MULT: usize = 64;

impl<T: Stack> Level<T> {
pub(crate) fn new(level: usize) -> Level<T> {
// Rust's derived implementations for arrays require that the value
// contained by the array be `Copy`. So, here we have to manually
// initialize every single slot.
macro_rules! s {
() => {
T::default()
};
}

Level {
level,
occupied: 0,
slot: [
// It does not look like the necessary traits are
// derived for [T; 64].
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
s!(),
],
slot: std::array::from_fn(|_| T::default()),
}
}

Expand Down

0 comments on commit bce9780

Please sign in to comment.