Skip to content

Commit

Permalink
Fix BitMap::new clippy: Do not create constant for type with interior… (
Browse files Browse the repository at this point in the history
#22)

* Fix BitMap::new clippy: Do not create constant for type with interior mutability

* Fix bitmap import

* Fix fmt in bitmap.rs

* Fix use of std::array::from_fn in bitmap
  • Loading branch information
NobodyXu authored Oct 19, 2024
1 parent 5796d8d commit f457b72
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/bitmap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use super::{thread_id::get_thread_id, SliceExt};

use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
use std::{
array,
sync::atomic::{AtomicUsize, Ordering::Relaxed},
};

fn compare_exchange(atomic: &AtomicUsize, curr: usize, new: usize) -> Result<(), usize> {
atomic
Expand All @@ -14,13 +17,7 @@ pub(crate) struct BitMap<const BITARRAY_LEN: usize>([AtomicUsize; BITARRAY_LEN])

impl<const BITARRAY_LEN: usize> BitMap<BITARRAY_LEN> {
pub(crate) fn new() -> Self {
// AtomicUsize is not Copyable, rustc suggests workaround
// by creating a const variable.

#[allow(clippy::declare_interior_mutable_const)]
const EMPTY_USIZE: AtomicUsize = AtomicUsize::new(0);

Self([EMPTY_USIZE; BITARRAY_LEN])
Self(array::from_fn(|_| AtomicUsize::new(0)))
}

/// # Safety
Expand Down

0 comments on commit f457b72

Please sign in to comment.