mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-10-02 14:54:30 +00:00
Merge #292
292: make Deque::pop_{front,back}_unchecked public r=japaric a=japaric closes #268 Co-authored-by: Jorge Aparicio <jorge.aparicio@ferrous-systems.com>
This commit is contained in:
commit
c2a022d9be
@ -10,10 +10,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
* Added support for AVR architecture.
|
* Added support for AVR architecture.
|
||||||
* Add Entry Api to IndexMap
|
* Add `entry` API to `IndexMap`
|
||||||
* Implement IntoIterator trait for Indexmap
|
* Implement `IntoIterator` trait for `Indexmap`
|
||||||
* Implement FromIterator for String
|
* Implement `FromIterator` for `String`
|
||||||
* Add first/last API to IndexMap and IndexSet
|
* Add `first` and `last` methods to `IndexMap` and `IndexSet`
|
||||||
|
* Add `pop_{front_back}_unchecked` methods to `Deque`
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
14
src/deque.rs
14
src/deque.rs
@ -271,12 +271,13 @@ impl<T, const N: usize> Deque<T, N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes an item from the front of the deque and returns it
|
/// Removes an item from the front of the deque and returns it, without checking that the deque
|
||||||
|
/// is not empty
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// This assumes the deque is not empty.
|
/// It's undefined behavior to call this on an empty deque
|
||||||
pub(crate) unsafe fn pop_front_unchecked(&mut self) -> T {
|
pub unsafe fn pop_front_unchecked(&mut self) -> T {
|
||||||
debug_assert!(!self.is_empty());
|
debug_assert!(!self.is_empty());
|
||||||
|
|
||||||
let index = self.front;
|
let index = self.front;
|
||||||
@ -285,12 +286,13 @@ impl<T, const N: usize> Deque<T, N> {
|
|||||||
(self.buffer.get_unchecked_mut(index).as_ptr() as *const T).read()
|
(self.buffer.get_unchecked_mut(index).as_ptr() as *const T).read()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes an item from the back of the deque and returns it
|
/// Removes an item from the back of the deque and returns it, without checking that the deque
|
||||||
|
/// is not empty
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// This assumes the deque is not empty.
|
/// It's undefined behavior to call this on an empty deque
|
||||||
pub(crate) unsafe fn pop_back_unchecked(&mut self) -> T {
|
pub unsafe fn pop_back_unchecked(&mut self) -> T {
|
||||||
debug_assert!(!self.is_empty());
|
debug_assert!(!self.is_empty());
|
||||||
|
|
||||||
self.full = false;
|
self.full = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user