Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub type BinaryHeapView<T, K> = BinaryHeapInner<T, K, ViewVecStorage<T>>;

impl<T, K, const N: usize> BinaryHeap<T, K, N> {
/* Constructors */
/// Creates an empty BinaryHeap as a $K-heap.
/// Creates an empty `BinaryHeap` as a $K-heap.
///
/// ```
/// use heapless::binary_heap::{BinaryHeap, Max};
Expand Down Expand Up @@ -222,7 +222,7 @@ where
/// assert!(heap.is_empty());
/// ```
pub fn clear(&mut self) {
self.data.clear()
self.data.clear();
}

/// Returns the length of the binary heap.
Expand Down
14 changes: 7 additions & 7 deletions src/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,15 @@ impl<T, S: VecStorage<T> + ?Sized> DequeInner<T, S> {
} else if self.back <= self.front {
(
slice::from_raw_parts(
self.buffer.borrow().as_ptr().add(self.front) as *const T,
self.buffer.borrow().as_ptr().add(self.front).cast::<T>(),
self.storage_capacity() - self.front,
),
slice::from_raw_parts(self.buffer.borrow().as_ptr() as *const T, self.back),
slice::from_raw_parts(self.buffer.borrow().as_ptr().cast::<T>(), self.back),
)
} else {
(
slice::from_raw_parts(
self.buffer.borrow().as_ptr().add(self.front) as *const T,
self.buffer.borrow().as_ptr().add(self.front).cast::<T>(),
self.back - self.front,
),
&[],
Expand All @@ -297,15 +297,15 @@ impl<T, S: VecStorage<T> + ?Sized> DequeInner<T, S> {
} else if self.back <= self.front {
(
slice::from_raw_parts_mut(
ptr.add(self.front) as *mut T,
ptr.add(self.front).cast::<T>(),
self.storage_capacity() - self.front,
),
slice::from_raw_parts_mut(ptr as *mut T, self.back),
slice::from_raw_parts_mut(ptr.cast::<T>(), self.back),
)
} else {
(
slice::from_raw_parts_mut(
ptr.add(self.front) as *mut T,
ptr.add(self.front).cast::<T>(),
self.back - self.front,
),
&mut [],
Expand Down Expand Up @@ -896,7 +896,7 @@ impl<T, S: VecStorage<T> + ?Sized> Extend<T> for DequeInner<T, S> {
}
impl<'a, T: 'a + Copy, S: VecStorage<T> + ?Sized> Extend<&'a T> for DequeInner<T, S> {
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
self.extend(iter.into_iter().copied())
self.extend(iter.into_iter().copied());
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/histbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ impl<T, S: HistBufStorage<T> + ?Sized> HistoryBufferInner<T, S> {
unsafe fn drop_contents(&mut self) {
unsafe {
ptr::drop_in_place(ptr::slice_from_raw_parts_mut(
self.data.borrow_mut().as_mut_ptr() as *mut T,
self.data.borrow_mut().as_mut_ptr().cast::<T>(),
self.len(),
))
));
}
}

Expand Down Expand Up @@ -446,7 +446,7 @@ impl<T, S: HistBufStorage<T> + ?Sized> HistoryBufferInner<T, S> {
/// Returns the array slice backing the buffer, without keeping track
/// of the write position. Therefore, the element order is unspecified.
pub fn as_slice(&self) -> &[T] {
unsafe { slice::from_raw_parts(self.data.borrow().as_ptr() as *const _, self.len()) }
unsafe { slice::from_raw_parts(self.data.borrow().as_ptr().cast(), self.len()) }
}

/// Returns a pair of slices which contain, in order, the contents of the buffer.
Expand All @@ -464,10 +464,10 @@ impl<T, S: HistBufStorage<T> + ?Sized> HistoryBufferInner<T, S> {
pub fn as_slices(&self) -> (&[T], &[T]) {
let buffer = self.as_slice();

if !self.filled {
(buffer, &[])
} else {
if self.filled {
(&buffer[self.write_at..], &buffer[..self.write_at])
} else {
(buffer, &[])
}
}

Expand Down Expand Up @@ -514,7 +514,7 @@ where
where
I: IntoIterator<Item = &'a T>,
{
self.extend(iter.into_iter().cloned())
self.extend(iter.into_iter().cloned());
}
}

Expand Down Expand Up @@ -791,7 +791,7 @@ mod tests {
assert_eq!(x.as_slice(), [5, 2, 3, 4]);
}

/// Test whether .as_slices() behaves as expected.
/// Test whether `.as_slices()` behaves as expected.
#[test]
fn as_slices() {
let mut buffer: HistoryBuffer<u8, 4> = HistoryBuffer::new();
Expand All @@ -807,7 +807,7 @@ mod tests {
extend_then_assert(b"123456", (b"34", b"56"));
}

/// Test whether .as_slices() and .oldest_ordered() produce elements in the same order.
/// Test whether `.as_slices()` and `.oldest_ordered()` produce elements in the same order.
#[test]
fn as_slices_equals_ordered() {
let mut buffer: HistoryBuffer<u8, 6> = HistoryBuffer::new();
Expand All @@ -818,7 +818,7 @@ mod tests {
assert_eq_iter(
[head, tail].iter().copied().flatten(),
buffer.oldest_ordered(),
)
);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/indexmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ where
where
I: IntoIterator<Item = (&'a K, &'a V)>,
{
self.extend(iterable.into_iter().map(|(&key, &value)| (key, value)))
self.extend(iterable.into_iter().map(|(&key, &value)| (key, value)));
}
}

Expand Down Expand Up @@ -1481,7 +1481,7 @@ mod tests {
mem::size_of::<u16>() // hash
) + // buckets
mem::size_of::<usize>() // entries.length
)
);
}

#[test]
Expand Down Expand Up @@ -1673,7 +1673,7 @@ mod tests {
assert_eq!(value, *v.insert(value).unwrap());
}
};
assert_eq!(value, *src.get(&key).unwrap())
assert_eq!(value, *src.get(&key).unwrap());
}

#[test]
Expand All @@ -1693,7 +1693,7 @@ mod tests {
panic!("Entry not found");
}
};
assert_eq!(value2, *src.get(&key).unwrap())
assert_eq!(value2, *src.get(&key).unwrap());
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/indexset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<T, S, const N: usize> IndexSet<T, S, N> {
/// assert!(v.is_empty());
/// ```
pub fn clear(&mut self) {
self.map.clear()
self.map.clear();
}
}

Expand Down Expand Up @@ -560,7 +560,7 @@ where
where
I: IntoIterator<Item = T>,
{
self.map.extend(iterable.into_iter().map(|k| (k, ())))
self.map.extend(iterable.into_iter().map(|k| (k, ())));
}
}

Expand All @@ -573,7 +573,7 @@ where
where
I: IntoIterator<Item = &'a T>,
{
self.extend(iterable.into_iter().cloned())
self.extend(iterable.into_iter().cloned());
}
}

Expand Down
21 changes: 13 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@
),
doc = "- [Object](pool::object::Object) -- objects managed by an object pool"
)]
//! - [BinaryHeap] -- priority queue
//! - [`BinaryHeap`] -- priority queue
//! - [Deque] -- double-ended queue
//! - [HistoryBuffer] -- similar to a write-only ring buffer
//! - [IndexMap] -- hash table
//! - [IndexSet] -- hash set
//! - [LinearMap]
//! - [sorted_linked_list::SortedLinkedList]
//! - [`HistoryBuffer`] -- similar to a write-only ring buffer
//! - [`IndexMap`] -- hash table
//! - [`IndexSet`] -- hash set
//! - [`LinearMap`]
//! - [`sorted_linked_list::SortedLinkedList`]
//! - [String]
//! - [Vec]
//! - [`mpmc::Q*`](mpmc) -- multiple producer multiple consumer lock-free queue
//! - [spsc] and [spsc::Queue] -- single producer single consumer lock-free queue
//! - [spsc] and [`spsc::Queue`] -- single producer single consumer lock-free queue
//!
//! # Minimum Supported Rust Version (MSRV)
//!
Expand All @@ -144,7 +144,12 @@
clippy::use_self,
clippy::too_long_first_doc_paragraph,
clippy::redundant_pub_crate,
clippy::option_if_let_else
clippy::option_if_let_else,
clippy::ptr_as_ptr,
clippy::ref_as_ptr,
clippy::doc_markdown,
clippy::semicolon_if_nothing_returned,
clippy::if_not_else
)]

pub use binary_heap::BinaryHeap;
Expand Down
2 changes: 1 addition & 1 deletion src/linear_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
/// assert!(map.is_empty());
/// ```
pub fn clear(&mut self) {
self.buffer.clear()
self.buffer.clear();
}

/// Returns true if the map contains a value for the specified key.
Expand Down
4 changes: 2 additions & 2 deletions src/mpmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ pub struct MpMcQueueInner<T, S: Storage> {

/// MPMC queue with a capacity for N elements
/// N must be a power of 2
/// The max value of N is u8::MAX - 1 if `mpmc_large` feature is not enabled.
/// The max value of N is `u8::MAX` - 1 if `mpmc_large` feature is not enabled.
pub type MpMcQueue<T, const N: usize> = MpMcQueueInner<T, OwnedStorage<N>>;

/// MPMC queue with a capacity for N elements
/// N must be a power of 2
/// The max value of N is u8::MAX - 1 if `mpmc_large` feature is not enabled.
/// The max value of N is `u8::MAX` - 1 if `mpmc_large` feature is not enabled.
pub type MpMcQueueView<T> = MpMcQueueInner<T, ViewStorage>;

impl<T, const N: usize> MpMcQueue<T, N> {
Expand Down
4 changes: 2 additions & 2 deletions src/pool/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub trait ArcPool: Sized {

/// Add a statically allocated memory block to the memory pool
fn manage(block: &'static mut ArcBlock<Self::Data>) {
Self::singleton().manage(block)
Self::singleton().manage(block);
}
}

Expand Down Expand Up @@ -315,7 +315,7 @@ where
where
H: Hasher,
{
(**self).hash(state)
(**self).hash(state);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/pool/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub trait BoxPool: Sized {

/// Add a statically allocated memory block to the memory pool
fn manage(block: &'static mut BoxBlock<Self::Data>) {
Self::singleton().manage(block)
Self::singleton().manage(block);
}
}

Expand Down Expand Up @@ -259,7 +259,7 @@ where
where
H: Hasher,
{
(**self).hash(state)
(**self).hash(state);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/pool/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub trait ObjectPool: Sized {

/// Adds a statically allocate object to the pool
fn manage(block: &'static mut ObjectBlock<Self::Data>) {
Self::singleton().manage(block)
Self::singleton().manage(block);
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ where
where
H: Hasher,
{
(**self).hash(state)
(**self).hash(state);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/pool/treiber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ where
/// - `node` must be a valid pointer
/// - aliasing rules must be enforced by the caller. e.g, the same `node` may not be pushed more than once
pub unsafe fn push(&self, node: NonNullPtr<N>) {
impl_::push(self, node)
impl_::push(self, node);
}

pub fn try_pop(&self) -> Option<NonNullPtr<N>> {
Expand Down
2 changes: 1 addition & 1 deletion src/pool/treiber/cas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ where
#[inline]
fn store(&self, value: Option<NonNullPtr<N>>, order: Ordering) {
self.inner
.store(value.map(NonNullPtr::into_inner).unwrap_or_default(), order)
.store(value.map(NonNullPtr::into_inner).unwrap_or_default(), order);
}
}

Expand Down
Loading