Struct utils_atomics::fill_queue::FillQueue
source · [−]alloc
only.Implementations
sourceimpl<T, A: Allocator> FillQueue<T, A>
impl<T, A: Allocator> FillQueue<T, A>
sourcepub fn allocator(&self) -> &A
pub fn allocator(&self) -> &A
Returns a reference to this queue’s allocator.
Example
#![feature(allocator_api)]
use utils_atomics::prelude::*;
use std::alloc::Global;
let queue = FillQueue::<i32>::new();
let alloc : &Global = queue.allocator();
sourcepub fn try_push(&self, v: T) -> Result<(), AllocError>
pub fn try_push(&self, v: T) -> Result<(), AllocError>
Uses atomic operations to push an element to the queue.
Errors
This method returns an error if alloc
fails to allocate the memory needed for the node.
Example
use utils_atomics::prelude::*;
let queue = FillQueue::<i32>::new();
assert!(queue.try_push(1).is_ok());
assert_eq!(queue.chop().next(), Some(1));
sourcepub fn try_push_mut(&mut self, v: T) -> Result<(), AllocError>
pub fn try_push_mut(&mut self, v: T) -> Result<(), AllocError>
Uses non-atomic operations to push an element to the queue.
Safety
This method is safe because the mutable reference guarantees we are the only thread that can access this queue.
Errors
This method returns an error if alloc
fails to allocate the memory needed for the node.
Example
use utils_atomics::prelude::*;
let mut queue = FillQueue::<i32>::new();
assert!(queue.try_push_mut(1).is_ok());
assert_eq!(queue.chop_mut().next(), Some(1));
sourceimpl<T, A: Allocator> FillQueue<T, A>
impl<T, A: Allocator> FillQueue<T, A>
sourcepub fn chop(&self) -> ChopIter<T, A>ⓘNotable traits for ChopIter<T, A>impl<T, A: Allocator> Iterator for ChopIter<T, A> type Item = T;
where
A: Clone,
pub fn chop(&self) -> ChopIter<T, A>ⓘNotable traits for ChopIter<T, A>impl<T, A: Allocator> Iterator for ChopIter<T, A> type Item = T;
where
A: Clone,
Returns a LIFO (Last In First Out) iterator over a chopped chunk of a FillQueue
.
The elements that find themselves inside the chopped region of the queue will be accessed through non-atomic operations.
Example
use utils_atomics::prelude::*;
let queue = FillQueue::<i32>::new();
queue.push(1);
queue.push(2);
queue.push(3);
let mut iter = queue.chop();
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), None)
sourcepub fn chop_mut(&mut self) -> ChopIter<T, A>ⓘNotable traits for ChopIter<T, A>impl<T, A: Allocator> Iterator for ChopIter<T, A> type Item = T;
where
A: Clone,
pub fn chop_mut(&mut self) -> ChopIter<T, A>ⓘNotable traits for ChopIter<T, A>impl<T, A: Allocator> Iterator for ChopIter<T, A> type Item = T;
where
A: Clone,
Returns a LIFO (Last In First Out) iterator over a chopped chunk of a FillQueue
. The chopping is done with non-atomic operations.
Safety
This method is safe because the mutable reference guarantees we are the only thread that can access this queue.
Example
use utils_atomics::prelude::*;
let mut queue = FillQueue::<i32>::new();
queue.push_mut(1);
queue.push_mut(2);
queue.push_mut(3);
let mut iter = queue.chop_mut();
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), None)
Auto Trait Implementations
impl<T, A> RefUnwindSafe for FillQueue<T, A>where
A: RefUnwindSafe,
impl<T, A> Send for FillQueue<T, A>where
A: Send,
impl<T, A> Sync for FillQueue<T, A>where
A: Sync,
impl<T, A> Unpin for FillQueue<T, A>where
A: Unpin,
impl<T, A> UnwindSafe for FillQueue<T, A>where
A: UnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more