Struct slice_queue::SliceQueue [−][src]
pub struct SliceQueue<T> { /* fields omitted */ }
Methods
impl<T> SliceQueue<T>
[src]
impl<T> SliceQueue<T>
pub fn new() -> Self
[src]
pub fn new() -> Self
Creates a new SliceQueue
Returns the new SliceQueue
pub fn with_capacity(n: usize) -> Self
[src]
pub fn with_capacity(n: usize) -> Self
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) -> Self
[src]
pub fn with_limit(limit: usize) -> Self
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 byself
.
Returns the new SliceQueue
pub fn set_auto_shrink_mode(&mut self, mode: AutoShrinkMode)
[src]
pub fn set_auto_shrink_mode(&mut self, mode: AutoShrinkMode)
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
pub fn auto_shrink_mode(&self) -> AutoShrinkMode
[src]
pub fn auto_shrink_mode(&self) -> AutoShrinkMode
The auto-shrink mode currently used
Returns true
if auto-shrink is enabled (which is the default state) or false
if it
was disabled
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.
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 byself
.
pub fn limit(&self) -> usize
[src]
pub fn limit(&self) -> usize
The current limit
Returns the current size-limit of self
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 auto_shrink(&mut self)
[src]
pub fn auto_shrink(&mut self)
Performs the auto-shrink action specified by self.auto_shrink_mode
Trait Implementations
impl<T: Default> Default for SliceQueue<T>
[src]
impl<T: Default> Default for SliceQueue<T>
ⓘImportant traits for SliceQueue<u8>fn default() -> SliceQueue<T>
[src]
fn default() -> SliceQueue<T>
Returns the "default value" for a type. Read more
impl<T> ReadableSliceQueue<T> for SliceQueue<T>
[src]
impl<T> ReadableSliceQueue<T> for SliceQueue<T>
fn len(&self) -> usize
[src]
fn len(&self) -> usize
The amount of elements stored
Returns the amount of elements stored in self
fn is_empty(&self) -> bool
[src]
fn is_empty(&self) -> bool
Checks if there are no elements stored
Returns either true
if self
is empty or false
otherwise
fn peek(&self) -> Option<&T>
[src]
fn peek(&self) -> Option<&T>
Take a look at the first element without consuming it
Returns either Some(element_ref)
if we have a first element or None
otherwise
fn peek_n(&self, n: usize) -> Result<&[T], &[T]>
[src]
fn peek_n(&self, n: usize) -> Result<&[T], &[T]>
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
fn pop(&mut self) -> Result<T, ()>
[src]
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
fn pop_n(&mut self, n: usize) -> Result<Vec<T>, Vec<T>>
[src]
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
fn pop_into(&mut self, dst: &mut [T]) -> Result<(), usize>
[src]
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
fn drop_n(&mut self, n: usize) -> Result<(), usize>
[src]
fn drop_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
impl Read for SliceQueue<u8>
[src]
impl Read for SliceQueue<u8>
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
[src]
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
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:
- 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.
- The buffer specified was 0 bytes in length.
This call never fails; the result is only used for trait-compatibility
unsafe fn initializer(&self) -> Initializer
[src]
unsafe fn initializer(&self) -> Initializer
read_initializer
)Determines if this Read
er can work with buffers of uninitialized memory. Read more
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
Read all bytes until EOF in this source, placing them into buf
. Read more
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Read all bytes until EOF in this source, appending them to buf
. Read more
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Read the exact number of bytes required to fill buf
. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
Creates a "by reference" adaptor for this instance of Read
. Read more
fn bytes(self) -> Bytes<Self>
1.0.0[src]
fn bytes(self) -> Bytes<Self>
Transforms this Read
instance to an [Iterator
] over its bytes. Read more
fn chars(self) -> Chars<Self>
[src]
fn chars(self) -> Chars<Self>
: 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
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
Creates an adaptor which will chain this stream with another. Read more
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
fn take(self, limit: u64) -> Take<Self>
Creates an adaptor which will read at most limit
bytes from it. Read more
impl<T> WriteableSliceQueue<T> for SliceQueue<T>
[src]
impl<T> WriteableSliceQueue<T> for SliceQueue<T>
fn remaining(&self) -> usize
[src]
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
fn reserve_n(&mut self, n: usize) -> Result<(), usize>
[src]
fn reserve_n(&mut self, n: usize) -> Result<(), usize>
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
.
fn reserved(&self) -> usize
[src]
fn reserved(&self) -> usize
The amount of elements that can be appended with out reallocating
Returns the amount of elements that can be appended with out reallocating
fn push(&mut self, element: T) -> Result<(), T>
[src]
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
fn push_n(&mut self, n: Vec<T>) -> Result<(), Vec<T>>
[src]
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
fn push_from(&mut self, src: &[T]) -> Result<(), usize> where
T: Clone,
[src]
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
fn push_in_place<E>(
&mut self,
n: usize,
push_fn: impl FnMut(&mut [T]) -> Result<usize, E>
) -> Result<usize, E> where
T: Default,
[src]
fn push_in_place<E>(
&mut self,
n: usize,
push_fn: impl FnMut(&mut [T]) -> Result<usize, E>
) -> Result<usize, E> where
T: Default,
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));
impl Write for SliceQueue<u8>
[src]
impl Write for SliceQueue<u8>
fn write(&mut self, buf: &[u8]) -> IoResult<usize>
[src]
fn write(&mut self, buf: &[u8]) -> IoResult<usize>
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:
- The limit was reached so that the
SliceQueue
cannot accept any more bytes. Note that this does not mean that theSliceQueue
will always no longer be able to accept bytes. - The buffer specified was 0 bytes in length.
This call never fails; the result is only used for trait-compatibility
fn flush(&mut self) -> IoResult<()>
[src]
fn flush(&mut self) -> IoResult<()>
This call does nothing (and thus never fails); it is only provided for trait-compatibility
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
Creates a "by reference" adaptor for this instance of Write
. Read more
impl<T: Debug> Debug for SliceQueue<T>
[src]
impl<T: Debug> Debug for SliceQueue<T>
fn fmt(&self, f: &mut Formatter) -> FmtResult
[src]
fn fmt(&self, f: &mut Formatter) -> FmtResult
Formats the value using the given formatter. Read more
impl<'a, T> From<&'a [T]> for SliceQueue<T> where
T: Clone,
[src]
impl<'a, T> From<&'a [T]> for SliceQueue<T> where
T: Clone,
impl<T> From<Vec<T>> for SliceQueue<T>
[src]
impl<T> From<Vec<T>> for SliceQueue<T>
impl<T> Into<Vec<T>> for SliceQueue<T>
[src]
impl<T> Into<Vec<T>> for SliceQueue<T>
impl<T> Clone for SliceQueue<T> where
T: Clone,
[src]
impl<T> Clone for SliceQueue<T> where
T: Clone,
fn clone(&self) -> Self
[src]
fn clone(&self) -> Self
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> 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, range: Range<usize>) -> &[T]
[src]
fn index(&self, range: Range<usize>) -> &[T]
Performs the 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, range: Range<usize>) -> &mut [T]
[src]
fn index_mut(&mut self, range: Range<usize>) -> &mut [T]
Performs the mutable 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, range: RangeFrom<usize>) -> &[T]
[src]
fn index(&self, range: RangeFrom<usize>) -> &[T]
Performs the 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, range: RangeFrom<usize>) -> &mut [T]
[src]
fn index_mut(&mut self, range: RangeFrom<usize>) -> &mut [T]
Performs the mutable 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, range: RangeTo<usize>) -> &[T]
[src]
fn index(&self, range: RangeTo<usize>) -> &[T]
Performs the 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, range: RangeTo<usize>) -> &mut [T]
[src]
fn index_mut(&mut self, range: RangeTo<usize>) -> &mut [T]
Performs the mutable indexing (container[index]
) operation.
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, range: RangeFull) -> &[T]
[src]
fn index(&self, range: RangeFull) -> &[T]
Performs the indexing (container[index]
) operation.
impl<T> IndexMut<RangeFull> for SliceQueue<T>
[src]
impl<T> IndexMut<RangeFull> for SliceQueue<T>
fn index_mut(&mut self, range: RangeFull) -> &mut [T]
[src]
fn index_mut(&mut self, range: RangeFull) -> &mut [T]
Performs the mutable 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, range: RangeInclusive<usize>) -> &[T]
[src]
fn index(&self, range: RangeInclusive<usize>) -> &[T]
Performs the 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, range: RangeInclusive<usize>) -> &mut [T]
[src]
fn index_mut(&mut self, range: RangeInclusive<usize>) -> &mut [T]
Performs the mutable 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, range: RangeToInclusive<usize>) -> &[T]
[src]
fn index(&self, range: RangeToInclusive<usize>) -> &[T]
Performs the 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, range: RangeToInclusive<usize>) -> &mut [T]
[src]
fn index_mut(&mut self, range: RangeToInclusive<usize>) -> &mut [T]
Performs the mutable 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.
fn index(&self, i: usize) -> &T
[src]
fn index(&self, i: usize) -> &T
Performs the indexing (container[index]
) operation.
impl<T> IndexMut<usize> for SliceQueue<T>
[src]
impl<T> IndexMut<usize> for SliceQueue<T>
fn 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> 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) -> &Self::Target
[src]
fn deref(&self) -> &Self::Target
Dereferences the value.
impl<T> DerefMut for SliceQueue<T>
[src]
impl<T> DerefMut for SliceQueue<T>
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,