Struct slice_queue::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)

Warning: Panics if limit is 0

Parameters:

  • limit: The limit to enforce. The limit indicates the maximum amount of elements that can be stored by self.

Returns the new SliceQueue

Sets the auto-shrink mode

This mode specifies how the SliceQueue should behave if elements are consumed

Parameters:

  • auto_shrink: The auto-shrink mode to use

The auto-shrink mode currently used

Returns true if auto-shrink is enabled (which is the default state) or false if it was disabled

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.

Warning: Panics if limit is 0

Parameters:

  • limit: The new limit to enforce. The limit indicates the maximum amount of elements that can be stored by self.

The current limit

Returns the current size-limit of self

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

Performs the auto-shrink action specified by self.auto_shrink_mode

Trait Implementations

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

Important traits for SliceQueue<u8>

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

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

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

Take a look at the first element without consuming it

Returns either Some(element_ref) if we have a first element or None otherwise

Take a look at the first n elements without consuming them

Parameters:

  • n: The amount of elements to peek at

Returns either Ok(element_refs) if there were n elements avaliable to peek at or Err(element_refs) if less elements were available

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

impl Read for SliceQueue<u8>
[src]

Pull some bytes from this source into the specified buffer, returning how many bytes were read.

It is guaranteed that for [Ok(n)] 0 <= n <= buf.len() is always true. A nonzero n value indicates that the buffer buf has been filled in with n bytes of data from this source. If n is 0, then it can indicate one of two scenarios:

  1. This reader has reached its "end of file" and will likely no longer be able to produce bytes. Note that this does not mean that the reader will always no longer be able to produce bytes.
  2. The buffer specified was 0 bytes in length.

This call never fails; the result is only used for trait-compatibility

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Read the exact number of bytes required to fill buf. Read more

Creates a "by reference" adaptor for this instance of Read. Read more

Transforms this Read instance to an [Iterator] over its bytes. Read more

Deprecated since 1.27.0

: Use str::from_utf8 instead: https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples

🔬 This is a nightly-only experimental API. (io)

the semantics of a partial read/write of where errors happen is currently unclear and may change

Transforms this Read instance to an [Iterator] over [char]s. Read more

Creates an adaptor which will chain this stream with another. Read more

Creates an adaptor which will read at most limit bytes from it. Read more

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

The amount of space remaining until self.limit is reached

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

Reserves an additional amount of memory to append n elements without reallocating

Does nothing if self.reserved is greater or equal n

Parameters:

  • n: The amount of elements that we should be able to append without reallocating

Returns either nothing if the space for n elements could be reserved or the amount of elements reserved if n was greater than self.remaining.

The amount of elements that can be appended with out reallocating

Returns the amount of elements that can be appended with out reallocating

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));

impl Write for SliceQueue<u8>
[src]

Write a buffer into this object, returning how many bytes were written.

This function will attempt to write the entire contents of buf, but the entire write may not succeed. A call to write represents at most one attempt to write to any wrapped object.

It is guaranteed that for [Ok(n)] 0 <= n <= buf.len() is always true. If n is 0, then it can indicate one of two scenarios:

  1. The limit was reached so that the SliceQueue cannot accept any more bytes. Note that this does not mean that the SliceQueue will always no longer be able to accept bytes.
  2. The buffer specified was 0 bytes in length.

This call never fails; the result is only used for trait-compatibility

This call does nothing (and thus never fails); it is only provided for trait-compatibility

Attempts to write an entire buffer into this write. Read more

Writes a formatted string into this writer, returning any error encountered. Read more

Creates a "by reference" adaptor for this instance of Write. Read more

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

Formats the value using the given formatter. Read more

impl<'a, T> From<&'a [T]> for SliceQueue<T> where
    T: Clone
[src]

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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> Index<Range<usize>> for SliceQueue<T>
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

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

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

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

The returned type after indexing.

Performs the indexing (container[index]) operation.

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

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

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

The returned type after indexing.

Performs the indexing (container[index]) operation.

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

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

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

The returned type after indexing.

Performs the indexing (container[index]) operation.

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

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

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

The returned type after indexing.

Performs the indexing (container[index]) operation.

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

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

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

The returned type after indexing.

Performs the indexing (container[index]) operation.

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

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

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

The returned type after indexing.

Performs the indexing (container[index]) operation.

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

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

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

The resulting type after dereferencing.

Dereferences the value.

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

Mutably dereferences the value.

Auto Trait Implementations

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

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