Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge ringbuffer traits #105

Merged
merged 7 commits into from
Jun 9, 2023
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
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ The ringbuffer crate provides safe fixed size circular buffers (ringbuffers) in

Implementations for three kinds of ringbuffers, with a mostly similar API are provided:

| type | description |
|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`AllocRingBuffer`][1] | Ringbuffer allocated on the heap at runtime. This ringbuffer is still fixed size. This requires alloc and the alloc feature. |
| [`GrowableAllocRingBuffer`][2] | Ringbuffer allocated on the heap at runtime. This ringbuffer can grow in size, and is implemented as an `alloc::VecDeque` internally. This requires alloc and the alloc feature. |
| [`ConstGenericRingBuffer`][3] | Ringbuffer which uses const generics to allocate on the stack. |
| type | description |
|--------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`AllocRingBuffer`][1] | Ringbuffer allocated on the heap at runtime. This ringbuffer is still fixed size. This requires the alloc feature. |
| [`GrowableAllocRingBuffer`][2] | Ringbuffer allocated on the heap at runtime. This ringbuffer can grow in size, and is implemented as an `alloc::VecDeque` internally. This requires the alloc feature. |
| [`ConstGenericRingBuffer`][3] | Ringbuffer which uses const generics to allocate on the stack. |

All of these ringbuffers also implement the [RingBuffer][4] trait for their shared API surface.

Expand All @@ -25,7 +25,8 @@ MSRV: Rust 1.59
# Usage

```rust
use ringbuffer::{AllocRingBuffer, RingBuffer, RingBufferExt, RingBufferWrite};
use ringbuffer::{AllocRingBuffer, RingBuffer};

fn main() {
let mut buffer = AllocRingBuffer::with_capacity(2);

Expand Down
9 changes: 4 additions & 5 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![cfg(not(tarpaulin))]
use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use ringbuffer::{AllocRingBuffer, ConstGenericRingBuffer, RingBufferExt, RingBufferWrite};
use ringbuffer::{AllocRingBuffer, ConstGenericRingBuffer, RingBuffer};

fn benchmark_push<T: RingBufferExt<i32>, F: Fn() -> T>(b: &mut Bencher, new: F) {
fn benchmark_push<T: RingBuffer<i32>, F: Fn() -> T>(b: &mut Bencher, new: F) {
b.iter(|| {
let mut rb = new();

Expand All @@ -15,7 +14,7 @@ fn benchmark_push<T: RingBufferExt<i32>, F: Fn() -> T>(b: &mut Bencher, new: F)
})
}

fn benchmark_push_dequeue<T: RingBufferExt<i32>, F: Fn() -> T>(b: &mut Bencher, new: F) {
fn benchmark_push_dequeue<T: RingBuffer<i32>, F: Fn() -> T>(b: &mut Bencher, new: F) {
b.iter(|| {
let mut rb = new();

Expand Down Expand Up @@ -49,7 +48,7 @@ fn benchmark_push_dequeue<T: RingBufferExt<i32>, F: Fn() -> T>(b: &mut Bencher,
})
}

fn benchmark_various<T: RingBufferExt<i32>, F: Fn() -> T>(b: &mut Bencher, new: F) {
fn benchmark_various<T: RingBuffer<i32>, F: Fn() -> T>(b: &mut Bencher, new: F) {
b.iter(|| {
let mut rb = new();

Expand Down
Loading