Struct timeout_io::SliceQueue[][src]

pub struct SliceQueue<T> { /* fields omitted */ }

Methods

impl<T> SliceQueue<T>
[src]

Creates a new SliceQueue

Returns the new SliceQueue

Creates a new SliceQueue with a preallocated capacity n

Parameters:

  • n: The capacity to preallocate

Returns the new SliceQueue

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 by self.

Returns the new SliceQueue

The amount of elements stored

Returns the amount of elements stored in self

Checks if there are no elements stored

Returns either true if self is empty or false otherwise

The allocated capacity

Returns the allocated capacity of self

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

Shrinks the allocated capacity if less than it's half is used or the allocated capacity is greater than self.limit.

Shrinks the allocated capacity as much as possible

The current limit

Returns the current size-limit of self

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 by self.

The amount of space remaining until self.limit is reached

Returns the amount of space remaining in self until self.limit is reached

Consumes the first element and returns it

Returns either Ok(element) if there was an element to consume or Err(()) otherwise

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

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

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

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

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

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

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:

  1. n default elements are inserted at the end
  2. push_fn is called with a mutable slice referencing the new elements and returns either the amount of elements pushed or an error
  3. 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 reserve
  • push_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]

Important traits for &'a mut R

Performs the mutable indexing (container[index]) operation.

impl<T> IndexMut<RangeInclusive<usize>> for SliceQueue<T>
[src]

Important traits for &'a [u8]

Performs the mutable indexing (container[index]) operation.

impl<T> IndexMut<RangeFull> for SliceQueue<T>
[src]

Important traits for &'a [u8]

Performs the mutable indexing (container[index]) operation.

impl<T> IndexMut<RangeTo<usize>> for SliceQueue<T>
[src]

Important traits for &'a [u8]

Performs the mutable indexing (container[index]) operation.

impl<T> IndexMut<RangeToInclusive<usize>> for SliceQueue<T>
[src]

Important traits for &'a [u8]

Performs the mutable indexing (container[index]) operation.

impl<T> IndexMut<RangeFrom<usize>> for SliceQueue<T>
[src]

Important traits for &'a [u8]

Performs the mutable indexing (container[index]) operation.

impl<T> IndexMut<Range<usize>> for SliceQueue<T>
[src]

Important traits for &'a [u8]

Performs the mutable indexing (container[index]) operation.

impl<T> Into<Vec<T>> for SliceQueue<T>
[src]

Important traits for Vec<u8>

Performs the conversion.

impl<T> Index<RangeFull> for SliceQueue<T>
[src]

The returned type after indexing.

Important traits for &'a [u8]

Performs the indexing (container[index]) operation.

impl<T> Index<RangeTo<usize>> for SliceQueue<T>
[src]

The returned type after indexing.

Important traits for &'a [u8]

Performs the indexing (container[index]) operation.

impl<T> Index<RangeInclusive<usize>> for SliceQueue<T>
[src]

The returned type after indexing.

Important traits for &'a [u8]

Performs the indexing (container[index]) operation.

impl<T> Index<usize> for SliceQueue<T>
[src]

The returned type after indexing.

Important traits for &'a mut R

Performs the indexing (container[index]) operation.

impl<T> Index<RangeFrom<usize>> for SliceQueue<T>
[src]

The returned type after indexing.

Important traits for &'a [u8]

Performs the indexing (container[index]) operation.

impl<T> Index<RangeToInclusive<usize>> for SliceQueue<T>
[src]

The returned type after indexing.

Important traits for &'a [u8]

Performs the indexing (container[index]) operation.

impl<T> Index<Range<usize>> for SliceQueue<T>
[src]

The returned type after indexing.

Important traits for &'a [u8]

Performs the indexing (container[index]) operation.

impl<T> DerefMut for SliceQueue<T>
[src]

Mutably dereferences the value.

impl<T> Clone for SliceQueue<T> where
    T: Clone
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T> Default for SliceQueue<T> where
    T: Default
[src]

Returns the "default value" for a type. Read more

impl<T> Debug for SliceQueue<T> where
    T: Debug
[src]

Formats the value using the given formatter. Read more

impl<T> Deref for SliceQueue<T>
[src]

The resulting type after dereferencing.

Dereferences the value.

impl<T> From<Vec<T>> for SliceQueue<T>
[src]

Performs the conversion.

Auto Trait Implementations

impl<T> Send for SliceQueue<T> where
    T: Send

impl<T> Sync for SliceQueue<T> where
    T: Sync