[][src]Struct cosey::Bytes

pub struct Bytes<N> where
    N: ArrayLength<u8>, 
{ /* fields omitted */ }

Methods

impl<N> Bytes<N> where
    N: ArrayLength<u8>, 
[src]

pub fn new() -> Bytes<N>[src]

Construct a new, empty Bytes<N>.

pub fn from<T>(bytes: T) -> Bytes<N> where
    T: Into<Vec<u8, N>>, 
[src]

Wrap existing bytes in a Bytes<N>.

pub fn into_vec(self) -> Vec<u8, N>[src]

Unwrap the vector of byte underlying this Bytes<N>.

pub fn try_from_slice(slice: &[u8]) -> Result<Bytes<N>, ()>[src]

pub fn insert_slice_at(&mut self, slice: &[u8], at: usize) -> Result<(), ()>[src]

pub fn resize_default(&mut self, new_len: usize) -> Result<(), ()>[src]

pub fn resize_to_capacity(&mut self)[src]

Methods from Deref<Target = Vec<u8, N>>

pub fn capacity(&self) -> usize

Returns the maximum number of elements the vector can hold

pub fn clear(&mut self)

Clears the vector, removing all values.

pub fn extend_from_slice(&mut self, other: &[T]) -> Result<(), ()> where
    T: Clone

Clones and appends all elements in a slice to the Vec.

Iterates over the slice other, clones each element, and then appends it to this Vec. The other vector is traversed in-order.

Examples

use heapless::Vec;
use heapless::consts::*;

let mut vec = Vec::<u8, U8>::new();
vec.push(1).unwrap();
vec.extend_from_slice(&[2, 3, 4]).unwrap();
assert_eq!(*vec, [1, 2, 3, 4]);

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

Removes the last element from a vector and return it, or None if it's empty

pub fn push(&mut self, item: T) -> Result<(), T>

Appends an item to the back of the collection

Returns back the item if the vector is full

pub fn truncate(&mut self, len: usize)

Shortens the vector, keeping the first len elements and dropping the rest.

pub fn resize(&mut self, new_len: usize, value: T) -> Result<(), ()> where
    T: Clone

Resizes the Vec in-place so that len is equal to new_len.

If new_len is greater than len, the Vec is extended by the difference, with each additional slot filled with value. If new_len is less than len, the Vec is simply truncated.

See also resize_default.

pub fn resize_default(&mut self, new_len: usize) -> Result<(), ()> where
    T: Clone + Default

Resizes the Vec in-place so that len is equal to new_len.

If new_len is greater than len, the Vec is extended by the difference, with each additional slot filled with Default::default(). If new_len is less than len, the Vec is simply truncated.

See also resize.

pub fn swap_remove(&mut self, index: usize) -> T

Removes an element from the vector and returns it.

The removed element is replaced by the last element of the vector.

This does not preserve ordering, but is O(1).

Panics

Panics if index is out of bounds.

Examples

use heapless::Vec;
use heapless::consts::*;

let mut v: Vec<_, U8> = Vec::new();
v.push("foo").unwrap();
v.push("bar").unwrap();
v.push("baz").unwrap();
v.push("qux").unwrap();

assert_eq!(v.swap_remove(1), "bar");
assert_eq!(&*v, ["foo", "qux", "baz"]);

assert_eq!(v.swap_remove(0), "foo");
assert_eq!(&*v, ["baz", "qux"]);

Trait Implementations

impl<N> AsMut<[u8]> for Bytes<N> where
    N: ArrayLength<u8>, 
[src]

impl<N> AsRef<[u8]> for Bytes<N> where
    N: ArrayLength<u8>, 
[src]

impl<N> Clone for Bytes<N> where
    N: Clone + ArrayLength<u8>, 
[src]

impl<N> Debug for Bytes<N> where
    N: ArrayLength<u8>, 
[src]

impl<N> Default for Bytes<N> where
    N: Default + ArrayLength<u8>, 
[src]

impl<N> Deref for Bytes<N> where
    N: ArrayLength<u8>, 
[src]

type Target = Vec<u8, N>

The resulting type after dereferencing.

impl<N> DerefMut for Bytes<N> where
    N: ArrayLength<u8>, 
[src]

impl<'de, N> Deserialize<'de> for Bytes<N> where
    N: ArrayLength<u8>, 
[src]

impl<N> Eq for Bytes<N> where
    N: Eq + ArrayLength<u8>, 
[src]

impl<N> Hash for Bytes<N> where
    N: ArrayLength<u8>, 
[src]

impl<'a, N> IntoIterator for &'a Bytes<N> where
    N: ArrayLength<u8>, 
[src]

type Item = &'a u8

The type of the elements being iterated over.

type IntoIter = <&'a [u8] as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?

impl<N> IntoIterator for Bytes<N> where
    N: ArrayLength<u8>, 
[src]

type Item = u8

The type of the elements being iterated over.

type IntoIter = <Vec<u8, N> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?

impl<'a, N> IntoIterator for &'a mut Bytes<N> where
    N: ArrayLength<u8>, 
[src]

type Item = &'a mut u8

The type of the elements being iterated over.

type IntoIter = <&'a mut [u8] as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?

impl<N, Rhs> PartialEq<Rhs> for Bytes<N> where
    N: ArrayLength<u8>,
    Rhs: AsRef<[u8]> + ?Sized
[src]

impl<N, Rhs> PartialOrd<Rhs> for Bytes<N> where
    N: ArrayLength<u8>,
    Rhs: AsRef<[u8]> + ?Sized
[src]

impl<N> Serialize for Bytes<N> where
    N: ArrayLength<u8>, 
[src]

impl<N> StructuralEq for Bytes<N> where
    N: ArrayLength<u8>, 
[src]

Auto Trait Implementations

impl<N> Send for Bytes<N>

impl<N> Sync for Bytes<N>

impl<N> Unpin for Bytes<N> where
    <N as ArrayLength<u8>>::ArrayType: 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> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

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

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> Same<T> for T

type Output = T

Should always be Self

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.