[][src]Struct ethox::managed::Partial

pub struct Partial<C> { /* fields omitted */ }

Refer to a part of some container.

Useful to create a dynamically sized storage over a statically sized backing buffer. This covers both byte buffers, such as packets, or general type buffers to be used similar to a vector.

Usage

Use a slice as a backing storage, logically initializing it gradually. Contrary to Vec the methods push and pop return a mutable reference to their element after they have succeeded instead of operating on values. They only change the logical length when called.

let mut elements = [0; 16];
let mut storage = Partial::new(&mut elements[..]);

for el in 0..10 {
    // Note that this drops an instance. That may be undesired.
    *storage.push().unwrap() = el;
}

This is useful as a generic payload representation as well. Resizing it is as simple as setting the current length unless the request can not be fulfilled with the current buffer size. Only in that case will it resize the underlying buffer.

Methods

impl<C> Partial<C>[src]

pub fn new(container: C) -> Self[src]

Make an instance that initially refers to an empty part.

pub fn inner(&self) -> &C[src]

Get a reference to the underlying buffer.

pub fn inner_mut(&mut self) -> &mut C[src]

Get a mutable reference to the underlying buffer.

pub fn into_inner(self) -> C[src]

Unwrap the inner buffer.

pub fn set_len_unchecked(&mut self, len: usize)[src]

Set the length to which to refer.

This does not check that the underlying storage actually has the claimed length. Setting a wrong value will typically lead to panicking later on.

pub fn len(&self) -> usize[src]

Get the claimed length.

Does not validate that a slice of the claimed length can actually be referred to.

pub fn is_empty(&self) -> bool[src]

Check if the list is empty.

pub fn inc(&mut self)[src]

Simply increase the length.

pub fn dec(&mut self)[src]

Simply decrease the length.

impl<C, T> Partial<C> where
    C: Deref<Target = [T]>, 
[src]

pub fn new_full(inner: C) -> Self[src]

Construct an instance referring to all of the inner container.

This sets the Partial's length based on the slice to which the container dereferences. If the containers impl of Deref is not consistent then some later calls may panic (but not this constructor).

pub fn capacity(&self) -> usize[src]

Check how many elements can be referred to at most.

This results in the length of the underlying container, not its capacity since the Partial is not aware of reallocation or other behaviour to change the underlying containers length.

pub fn as_slice(&self) -> &[T][src]

Get the logically active elements as a slice.

pub fn get<'a, I>(&'a self, idx: I) -> Option<&'a I::Output> where
    I: SliceIndex<[T]>,
    T: 'a, 
[src]

Retrieve the logical path of the underlying container if possible.

This is a non-panicking variant of index access.

impl<C, T> Partial<C> where
    C: Deref<Target = [T]> + DerefMut
[src]

pub fn init(&mut self) -> Option<&mut T>[src]

Get a mutable reference to the element that would be pushed next.

pub fn insert_at(&mut self, pos: usize) -> Option<&mut T>[src]

Insert the next element at some position.

Panics

This method panics if the pos is larger than the current length.

pub fn push(&mut self) -> Option<&mut T>[src]

Insert behind the last element.

pub fn remove_at(&mut self, pos: usize) -> Option<&mut T>[src]

Remove the element at a position.

pub fn pop(&mut self) -> Option<&mut T>[src]

Remove the last element.

pub fn as_mut_slice(&mut self) -> &mut [T][src]

Get the logically active elements as a mutable slice.

pub fn get_mut<'a, I>(&'a mut self, idx: I) -> Option<&'a mut I::Output> where
    I: SliceIndex<[T]>,
    T: 'a, 
[src]

Retrieve the logical path of the underlying container if possible.

This is a non-panicking variant of index access.

Trait Implementations

impl<C, T> AsMut<[T]> for Partial<C> where
    C: AsMut<[T]>, 
[src]

impl<C, T> AsRef<[T]> for Partial<C> where
    C: AsRef<[T]>, 
[src]

impl<C: Clone> Clone for Partial<C>[src]

impl<C: Debug> Debug for Partial<C>[src]

impl<C, T> Deref for Partial<C> where
    C: Deref<Target = [T]>, 
[src]

type Target = [T]

The resulting type after dereferencing.

impl<C, T> DerefMut for Partial<C> where
    C: Deref<Target = [T]> + DerefMut
[src]

impl<C: Payload> Payload for Partial<C>[src]

impl<C: PayloadMut> PayloadMut for Partial<C>[src]

Auto Trait Implementations

impl<C> Send for Partial<C> where
    C: Send

impl<C> Sync for Partial<C> where
    C: Sync

impl<C> Unpin for Partial<C> where
    C: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.