Struct timeout_io::SliceQueue [−][src]
pub struct SliceQueue<T> { /* fields omitted */ }
Methods
impl<T> SliceQueue<T>
[src]
impl<T> SliceQueue<T>
pub fn new() -> SliceQueue<T>
[src]
pub fn new() -> SliceQueue<T>
Creates a new SliceQueue
Returns the new SliceQueue
pub fn with_capacity(n: usize) -> SliceQueue<T>
[src]
pub fn with_capacity(n: usize) -> SliceQueue<T>
Creates a new SliceQueue
with a preallocated capacity n
Parameters:
n
: The capacity to preallocate
Returns the new SliceQueue
pub fn with_limit(limit: usize) -> SliceQueue<T>
[src]
pub fn with_limit(limit: usize) -> SliceQueue<T>
Creates a new SliceQueue
with a predefined limit
(the default limit is usize::MAX
)
Parameters:
limit
: The limit to enforce. The limit indicates the maximum amount of elements that can be stored byself
.
Returns the new SliceQueue
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
The amount of elements stored
Returns the amount of elements stored in self
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Checks if there are no elements stored
Returns either true
if self
is empty or false
otherwise
pub fn capacity(&self) -> usize
[src]
pub fn capacity(&self) -> usize
The allocated capacity
Returns the allocated capacity of self
pub fn reserve(&mut self, additional_element_count: usize)
[src]
pub fn reserve(&mut self, additional_element_count: usize)
Reserves an additional amount of memory to push additional_element_count
elements without
reallocating
Parameters:
additional_element_count
: The amount of elements that we should be able to append without reallocating
pub fn shrink_opportunistic(&mut self)
[src]
pub fn shrink_opportunistic(&mut self)
Shrinks the allocated capacity if less than it's half is used or the allocated capacity is
greater than self.limit
.
pub fn shrink_to_fit(&mut self)
[src]
pub fn shrink_to_fit(&mut self)
Shrinks the allocated capacity as much as possible
pub fn limit(&self) -> usize
[src]
pub fn limit(&self) -> usize
The current limit
Returns the current size-limit of self
pub fn set_limit(&mut self, limit: usize)
[src]
pub fn set_limit(&mut self, limit: usize)
Sets a new limit (the default limit is usize::MAX
)
Info: The limit is only enforced during the push*
-calls. If the current length exceeds
the new limit, nothing happens until a push*
-call would exceed the limit.
Parameters:
limit
: The new limit to enforce. The limit indicates the maximum amount of elements that can be stored byself
.
pub fn remaining(&self) -> usize
[src]
pub fn remaining(&self) -> usize
The amount of space remaining until self.limit
is reached
Returns the amount of space remaining in self
until self.limit
is reached
pub fn pop(&mut self) -> Result<T, ()>
[src]
pub fn pop(&mut self) -> Result<T, ()>
Consumes the first element and returns it
Returns either Ok(element)
if there was an element to consume or Err(())
otherwise
pub fn pop_n(&mut self, n: usize) -> Result<Vec<T>, Vec<T>>
[src]
pub fn pop_n(&mut self, n: usize) -> Result<Vec<T>, Vec<T>>
Consumes the first n
elements and returns them
Parameters:
n
: The amount of elements to consume
Returns either Ok(elements)
if there were n
elements avaliable to consume or
Err(elements)
if less elements were available
pub fn pop_into(&mut self, dst: &mut [T]) -> Result<(), usize>
[src]
pub fn pop_into(&mut self, dst: &mut [T]) -> Result<(), usize>
Consumes the first dst.len()
and moves them into dst
Parameters:
dst
: The target to move the elements into
Returns either Ok(())
if dst
was filled completely or Err(element_count)
if
only element_count
elements were moved
pub fn discard_n(&mut self, n: usize) -> Result<(), usize>
[src]
pub fn discard_n(&mut self, n: usize) -> Result<(), usize>
Discards the first n
elements
Parameters:
n
: The amount of elements to discard
Returns either Ok(())
if n
elements were discarded or Err(element_count)
if
only element_count
elements were discarded
pub fn push(&mut self, element: T) -> Result<(), T>
[src]
pub fn push(&mut self, element: T) -> Result<(), T>
Appends element
at the end
Parameters:
element
: The element to append at the end
Returns either Ok(())
if the element was pushed successfully or Err(element)
if
element
was not appended because self.limit
would have been exceeded
pub fn push_n(&mut self, n: Vec<T>) -> Result<(), Vec<T>>
[src]
pub fn push_n(&mut self, n: Vec<T>) -> Result<(), Vec<T>>
Appends n
at the end
Parameters:
n
: The n elements to append at the end
Returns either Ok(())
if n
was appended completely or Err(remaining_elements)
if n
was only appended partially because self.limit
would have been exceeded
pub fn push_from(&mut self, src: &[T]) -> Result<(), usize> where
T: Clone,
[src]
pub fn push_from(&mut self, src: &[T]) -> Result<(), usize> where
T: Clone,
Clones and appends the elements in src
at the end
Parameters:
src
: A slice containing the elements to clone and append
Returns either Ok(())
if src
was appended completely or
Err(remaining_element_count)
if src
was only appended partially because self.limit
would have been exceeded
pub fn push_in_place<E, impl FnMut(&mut [T]) -> Result>(
&mut self,
n: usize,
push_fn: impl FnMut(&mut [T]) -> Result
) -> Result<usize, E> where
T: Default,
impl FnMut(&mut [T]) -> Result: FnMut(&mut [T]) -> Result<usize, E>,
[src]
pub fn push_in_place<E, impl FnMut(&mut [T]) -> Result>(
&mut self,
n: usize,
push_fn: impl FnMut(&mut [T]) -> Result
) -> Result<usize, E> where
T: Default,
impl FnMut(&mut [T]) -> Result: FnMut(&mut [T]) -> Result<usize, E>,
Calls push_fn
to push up to n
elements in place
Warning: This function panics if self.limit
is exceeded
The function works like this:
n
default elements are inserted at the endpush_fn
is called with a mutable slice referencing the new elements and returns either the amount of elements pushed or an error- If the amount of elements pushed is smaller than
n
or an error occurred, the unused default elements are removed again
Parameters:
n
: The amount of bytes to reservepush_fn
: The pushing callback
Returns either the amount of elements pushed or the error push_fn
returned
Example:
let mut slice_queue = SliceQueue::new(); // Successful push slice_queue.push_in_place(7, |buffer: &mut[usize]| -> Result<usize, ()> { (0..4).for_each(|i| buffer[i] = i); Ok(4) }); assert_eq!(slice_queue.len(), 4); (0..4).for_each(|i| assert_eq!(slice_queue[i], i)); // Failed push slice_queue.push_in_place(7, |buffer: &mut[usize]| -> Result<usize, ()> { (0..4).for_each(|i| buffer[i] = i + 7); Err(()) }); assert_eq!(slice_queue.len(), 4); (0..4).for_each(|i| assert_eq!(slice_queue[i], i));
Trait Implementations
impl<T> IndexMut<usize> for SliceQueue<T>
[src]
impl<T> IndexMut<usize> for SliceQueue<T>
ⓘImportant traits for &'a mut Rfn index_mut(&mut self, i: usize) -> &mut T
[src]
fn index_mut(&mut self, i: usize) -> &mut T
Performs the mutable indexing (container[index]
) operation.
impl<T> IndexMut<RangeInclusive<usize>> for SliceQueue<T>
[src]
impl<T> IndexMut<RangeInclusive<usize>> for SliceQueue<T>
fn index_mut(&mut self, bounds: RangeInclusive<usize>) -> &mut [T]
[src]
fn index_mut(&mut self, bounds: RangeInclusive<usize>) -> &mut [T]
Performs the mutable indexing (container[index]
) operation.
impl<T> IndexMut<RangeFull> for SliceQueue<T>
[src]
impl<T> IndexMut<RangeFull> for SliceQueue<T>
fn index_mut(&mut self, bounds: RangeFull) -> &mut [T]
[src]
fn index_mut(&mut self, bounds: RangeFull) -> &mut [T]
Performs the mutable indexing (container[index]
) operation.
impl<T> IndexMut<RangeTo<usize>> for SliceQueue<T>
[src]
impl<T> IndexMut<RangeTo<usize>> for SliceQueue<T>
fn index_mut(&mut self, bounds: RangeTo<usize>) -> &mut [T]
[src]
fn index_mut(&mut self, bounds: RangeTo<usize>) -> &mut [T]
Performs the mutable indexing (container[index]
) operation.
impl<T> IndexMut<RangeToInclusive<usize>> for SliceQueue<T>
[src]
impl<T> IndexMut<RangeToInclusive<usize>> for SliceQueue<T>
fn index_mut(&mut self, bounds: RangeToInclusive<usize>) -> &mut [T]
[src]
fn index_mut(&mut self, bounds: RangeToInclusive<usize>) -> &mut [T]
Performs the mutable indexing (container[index]
) operation.
impl<T> IndexMut<RangeFrom<usize>> for SliceQueue<T>
[src]
impl<T> IndexMut<RangeFrom<usize>> for SliceQueue<T>
fn index_mut(&mut self, bounds: RangeFrom<usize>) -> &mut [T]
[src]
fn index_mut(&mut self, bounds: RangeFrom<usize>) -> &mut [T]
Performs the mutable indexing (container[index]
) operation.
impl<T> IndexMut<Range<usize>> for SliceQueue<T>
[src]
impl<T> IndexMut<Range<usize>> for SliceQueue<T>
fn index_mut(&mut self, bounds: Range<usize>) -> &mut [T]
[src]
fn index_mut(&mut self, bounds: Range<usize>) -> &mut [T]
Performs the mutable indexing (container[index]
) operation.
impl<T> Into<Vec<T>> for SliceQueue<T>
[src]
impl<T> Into<Vec<T>> for SliceQueue<T>
impl<T> Index<RangeFull> for SliceQueue<T>
[src]
impl<T> Index<RangeFull> for SliceQueue<T>
type Output = [T]
The returned type after indexing.
fn index(&self, bounds: RangeFull) -> &[T]
[src]
fn index(&self, bounds: RangeFull) -> &[T]
Performs the indexing (container[index]
) operation.
impl<T> Index<RangeTo<usize>> for SliceQueue<T>
[src]
impl<T> Index<RangeTo<usize>> for SliceQueue<T>
type Output = [T]
The returned type after indexing.
fn index(&self, bounds: RangeTo<usize>) -> &[T]
[src]
fn index(&self, bounds: RangeTo<usize>) -> &[T]
Performs the indexing (container[index]
) operation.
impl<T> Index<RangeInclusive<usize>> for SliceQueue<T>
[src]
impl<T> Index<RangeInclusive<usize>> for SliceQueue<T>
type Output = [T]
The returned type after indexing.
fn index(&self, bounds: RangeInclusive<usize>) -> &[T]
[src]
fn index(&self, bounds: RangeInclusive<usize>) -> &[T]
Performs the indexing (container[index]
) operation.
impl<T> Index<usize> for SliceQueue<T>
[src]
impl<T> Index<usize> for SliceQueue<T>
type Output = T
The returned type after indexing.
ⓘImportant traits for &'a mut Rfn index(&self, i: usize) -> &T
[src]
fn index(&self, i: usize) -> &T
Performs the indexing (container[index]
) operation.
impl<T> Index<RangeFrom<usize>> for SliceQueue<T>
[src]
impl<T> Index<RangeFrom<usize>> for SliceQueue<T>
type Output = [T]
The returned type after indexing.
fn index(&self, bounds: RangeFrom<usize>) -> &[T]
[src]
fn index(&self, bounds: RangeFrom<usize>) -> &[T]
Performs the indexing (container[index]
) operation.
impl<T> Index<RangeToInclusive<usize>> for SliceQueue<T>
[src]
impl<T> Index<RangeToInclusive<usize>> for SliceQueue<T>
type Output = [T]
The returned type after indexing.
fn index(&self, bounds: RangeToInclusive<usize>) -> &[T]
[src]
fn index(&self, bounds: RangeToInclusive<usize>) -> &[T]
Performs the indexing (container[index]
) operation.
impl<T> Index<Range<usize>> for SliceQueue<T>
[src]
impl<T> Index<Range<usize>> for SliceQueue<T>
type Output = [T]
The returned type after indexing.
fn index(&self, bounds: Range<usize>) -> &[T]
[src]
fn index(&self, bounds: Range<usize>) -> &[T]
Performs the indexing (container[index]
) operation.
impl<T> DerefMut for SliceQueue<T>
[src]
impl<T> DerefMut for SliceQueue<T>
fn deref_mut(&mut self) -> &mut <SliceQueue<T> as Deref>::Target
[src]
fn deref_mut(&mut self) -> &mut <SliceQueue<T> as Deref>::Target
Mutably dereferences the value.
impl<T> Clone for SliceQueue<T> where
T: Clone,
[src]
impl<T> Clone for SliceQueue<T> where
T: Clone,
fn clone(&self) -> SliceQueue<T>
[src]
fn clone(&self) -> SliceQueue<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T> Default for SliceQueue<T> where
T: Default,
[src]
impl<T> Default for SliceQueue<T> where
T: Default,
fn default() -> SliceQueue<T>
[src]
fn default() -> SliceQueue<T>
Returns the "default value" for a type. Read more
impl<T> Debug for SliceQueue<T> where
T: Debug,
[src]
impl<T> Debug for SliceQueue<T> where
T: Debug,
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl<T> Deref for SliceQueue<T>
[src]
impl<T> Deref for SliceQueue<T>
type Target = <Vec<T> as Deref>::Target
The resulting type after dereferencing.
fn deref(&self) -> &<SliceQueue<T> as Deref>::Target
[src]
fn deref(&self) -> &<SliceQueue<T> as Deref>::Target
Dereferences the value.
impl<T> From<Vec<T>> for SliceQueue<T>
[src]
impl<T> From<Vec<T>> for SliceQueue<T>
fn from(vec: Vec<T>) -> SliceQueue<T>
[src]
fn from(vec: Vec<T>) -> SliceQueue<T>
Performs the conversion.
Auto Trait Implementations
impl<T> Send for SliceQueue<T> where
T: Send,
impl<T> Send for SliceQueue<T> where
T: Send,
impl<T> Sync for SliceQueue<T> where
T: Sync,
impl<T> Sync for SliceQueue<T> where
T: Sync,