Skip to content

Commit

Permalink
Merge pull request #95 from NULLx76/remove-deprecated
Browse files Browse the repository at this point in the history
remove deprecated methods for 1.0
  • Loading branch information
jdonszelmann authored Sep 15, 2023
2 parents adb6802 + 110f21e commit 1ae229d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 61 deletions.
31 changes: 9 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,28 +695,6 @@ mod tests {
test_get_relative_mut_zero_length(ConstGenericRingBuffer::<i32, 8>::new());
}

#[test]
#[allow(deprecated)]
fn run_test_get_absolute() {
fn test_get_absolute(mut b: impl RingBuffer<i32>) {
b.push(0);
b.push(1);

// [0, ...]
// ^
// [0, 1, ...]
// ^
// get[0] = 0
// get[1] = 1
assert_eq!(b.get_absolute(0).unwrap(), &0);
assert_eq!(b.get_absolute(1).unwrap(), &1);
assert!(b.get_absolute(2).is_none());
}

test_get_absolute(AllocRingBuffer::with_capacity(8));
test_get_absolute(ConstGenericRingBuffer::<i32, 8>::new());
}

#[test]
fn run_test_from_iterator() {
fn test_from_iterator<T: RingBuffer<i32> + FromIterator<i32>>() {
Expand Down Expand Up @@ -1272,6 +1250,15 @@ mod tests {
next_back_test_mut(AllocRingBuffer::new(8));
next_back_test_mut(GrowableAllocRingBuffer::with_capacity(8));
}

#[test]
fn test_fill() {
let mut b = AllocRingBuffer::from([vec![1], vec![2]]);
b.fill(vec![2]);
assert_eq!(b.dequeue(), Some(vec![2]));
assert_eq!(b.dequeue(), Some(vec![2]));
}

#[test]
fn run_test_fill() {
fn test_fill(mut rb: impl RingBuffer<i32>) {
Expand Down
40 changes: 9 additions & 31 deletions src/ringbuffer_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ pub unsafe trait RingBuffer<T>:
}

/// Raw pointer version of len
/// Safety: ONLY SAFE WHEN self is a *mut to to an implementor of RingBuffer
///
/// # Safety
/// ONLY SAFE WHEN self is a *mut to to an implementor of `RingBuffer`
#[doc(hidden)]
unsafe fn ptr_len(rb: *const Self) -> usize;

Expand All @@ -54,7 +56,9 @@ pub unsafe trait RingBuffer<T>:
}

/// Raw pointer version of capacity.
/// Safety: ONLY SAFE WHEN self is a *mut to to an implementor of RingBuffer
///
/// # Safety
/// ONLY SAFE WHEN self is a *mut to to an implementor of `RingBuffer`
#[doc(hidden)]
unsafe fn ptr_capacity(rb: *const Self) -> usize;

Expand Down Expand Up @@ -137,18 +141,12 @@ pub unsafe trait RingBuffer<T>:
}

/// same as [`get_mut`](RingBuffer::get_mut) but on raw pointers.
/// Safety: ONLY SAFE WHEN self is a *mut to to an implementor of RingBuffer
///
/// # Safety
/// ONLY SAFE WHEN self is a *mut to to an implementor of `RingBuffer`
#[doc(hidden)]
unsafe fn ptr_get_mut(rb: *mut Self, index: isize) -> Option<*mut T>;

/// Gets a value relative to the start of the array (rarely useful, usually you want [`Self::get`])
#[deprecated = "cannot find a valid usecase for this, hard to implement for some ringbuffers"]
fn get_absolute(&self, index: usize) -> Option<&T>;

/// Gets a value mutably relative to the start of the array (rarely useful, usually you want [`Self::get_mut`])
#[deprecated = "cannot find a valid usecase for this, hard to implement for some ringbuffers"]
fn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>;

/// Returns the value at the current index.
/// This is the value that will be overwritten by the next push and also the value pushed
/// the longest ago. (alias of [`Self::front`])
Expand Down Expand Up @@ -468,26 +466,6 @@ macro_rules! impl_ringbuffer_ext {
})
}

#[inline]
fn get_absolute(&self, index: usize) -> Option<&T> {
let read = $mask(self.capacity(), self.$readptr);
let write = $mask(self.capacity(), self.$writeptr);
(index >= read && index < write).then(|| unsafe {
// SAFETY: index has been checked against $mask to be within bounds
$get_unchecked(self, index)
})
}

#[inline]
fn get_absolute_mut(&mut self, index: usize) -> Option<&mut T> {
(index >= $mask(self.capacity(), self.$readptr)
&& index < $mask(self.capacity(), self.$writeptr))
.then(move || unsafe {
// SAFETY: index has been checked against $mask to be within bounds
&mut *$get_unchecked_mut(self, index)
})
}

#[inline]
fn clear(&mut self) {
for i in self.drain() {
Expand Down
8 changes: 0 additions & 8 deletions src/with_alloc/vecdeque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,6 @@ unsafe impl<T> RingBuffer<T> for GrowableAllocRingBuffer<T> {
}
.map(|i| i as *mut T)
}

fn get_absolute(&self, _index: usize) -> Option<&T> {
unimplemented!()
}

fn get_absolute_mut(&mut self, _index: usize) -> Option<&mut T> {
unimplemented!()
}
}

impl<T> Extend<T> for GrowableAllocRingBuffer<T> {
Expand Down

1 comment on commit 1ae229d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.