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
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ mod with_alloc;
#[cfg(feature = "alloc")]
pub use with_alloc::alloc_ringbuffer::AllocRingBuffer;
#[cfg(feature = "alloc")]
pub use with_alloc::alloc_ringbuffer::{NonPowerOfTwo, PowerOfTwo, RingbufferSize};
#[cfg(feature = "alloc")]
pub use with_alloc::vecdeque::GrowableAllocRingBuffer;

mod with_const_generics;
Expand Down
9 changes: 9 additions & 0 deletions src/with_alloc/alloc_ringbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ use core::marker::PhantomData;
use core::ptr;

#[derive(Debug, Copy, Clone)]
/// Represents that an alloc ringbuffer must have a size that's a power of two.
/// This means slightly more optimizations can be performed, but it is less flexible.
pub struct PowerOfTwo;

#[derive(Debug, Copy, Clone)]
/// Represents that an alloc ringbuffer can have a size that's not a power of two.
/// This means slightly fewer optimizations can be performed, but it is more flexible.
pub struct NonPowerOfTwo;
mod private {
use crate::with_alloc::alloc_ringbuffer::{NonPowerOfTwo, PowerOfTwo};
Expand All @@ -23,8 +27,13 @@ mod private {
impl Sealed for NonPowerOfTwo {}
}

/// Sealed trait with two implementations that represent the kinds of sizes a ringbuffer can have
/// *[`NonPowerOfTwo`]
/// *[`PowerOfTwo`]
pub trait RingbufferSize: private::Sealed {
/// the mask function to use for wrapping indices in the ringbuffer
fn mask(cap: usize, index: usize) -> usize;
/// true in [`PowerOfTwo`], false in [`NonPowerOfTwo`]
fn must_be_power_of_two() -> bool;
}

Expand Down