Struct iso7816::Bytes [−][src]
pub struct Bytes<N> where
N: ArrayLength<u8>, { /* fields omitted */ }
Implementations
impl<N> Bytes<N> where
N: ArrayLength<u8>,
[src]
impl<N> Bytes<N> where
N: ArrayLength<u8>,
[src]pub fn from<T>(bytes: T) -> Bytes<N> where
T: Into<Vec<u8, N>>,
[src]
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_inner(self) -> Vec<u8, N>
[src]
pub fn into_inner(self) -> Vec<u8, N>
[src]Unwraps the Vec<u8, N>, same as into_vec
.
pub fn as_mut_slice(&mut self) -> &mut [u8]
[src]
pub fn as_mut_slice(&mut self) -> &mut [u8]
[src]Returns a mutable slice view.
pub fn try_convert_into<M>(&self) -> Result<Bytes<M>, ()> where
M: ArrayLength<u8>,
[src]
pub fn try_convert_into<M>(&self) -> Result<Bytes<M>, ()> where
M: ArrayLength<u8>,
[src]Low-noise conversion between lengths.
We can’t implement TryInto since it would clash with blanket implementations.
pub fn try_from_slice(slice: &[u8]) -> Result<Bytes<N>, ()>
[src]
pub fn try_from<E>(
f: impl FnOnce(&mut [u8]) -> Result<usize, E>
) -> Result<Bytes<N>, E>
[src]
pub fn try_from<E>(
f: impl FnOnce(&mut [u8]) -> Result<usize, E>
) -> Result<Bytes<N>, E>
[src]Some APIs offer an interface of the form f(&mut [u8]) -> Result<usize, E>
,
with the contract that the Ok-value signals how many bytes were written.
This constructor allows wrapping such interfaces in a more ergonomic way,
returning a Bytes willed using f
.
It seems it’s not possible to do this as an actual TryFrom
implementation.
pub fn insert_slice_at(&mut self, slice: &[u8], at: usize) -> Result<(), ()>
[src]
pub fn insert(&mut self, index: usize, item: u8) -> Result<(), u8>
[src]
pub fn remove(&mut self, index: usize) -> Result<u8, ()>
[src]
pub fn resize_default(&mut self, new_len: usize) -> Result<(), ()>
[src]
pub fn resize_to_capacity(&mut self)
[src]
pub fn to_bytes<M>(&self) -> Bytes<M> where
M: ArrayLength<u8> + IsGreaterOrEqual<N, Output = B1>,
[src]
pub fn to_bytes<M>(&self) -> Bytes<M> where
M: ArrayLength<u8> + IsGreaterOrEqual<N, Output = B1>,
[src]Clone into at least same size byte buffer.
pub fn try_to_bytes<M>(&self) -> Result<Bytes<M>, ()> where
M: ArrayLength<u8>,
[src]
pub fn try_to_bytes<M>(&self) -> Result<Bytes<M>, ()> where
M: ArrayLength<u8>,
[src]Fallible conversion into differently sized byte buffer.
Methods from Deref<Target = Vec<u8, N>>
pub fn extend_from_slice(&mut self, other: &[T]) -> Result<(), ()> where
T: Clone,
[src]
pub fn extend_from_slice(&mut self, other: &[T]) -> Result<(), ()> where
T: Clone,
[src]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>
[src]
pub fn pop(&mut self) -> Option<T>
[src]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>
[src]
pub fn push(&mut self, item: T) -> Result<(), T>
[src]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)
[src]
pub fn truncate(&mut self, len: usize)
[src]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,
[src]
pub fn resize(&mut self, new_len: usize, value: T) -> Result<(), ()> where
T: Clone,
[src]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,
[src]
pub fn resize_default(&mut self, new_len: usize) -> Result<(), ()> where
T: Clone + Default,
[src]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 unsafe fn set_len(&mut self, new_len: usize)
[src]
pub unsafe fn set_len(&mut self, new_len: usize)
[src]Forces the length of the vector to new_len
.
This is a low-level operation that maintains none of the normal
invariants of the type. Normally changing the length of a vector
is done using one of the safe operations instead, such as
truncate
, resize
, extend
, or clear
.
Safety
new_len
must be less than or equal tocapacity()
.- The elements at
old_len..new_len
must be initialized.
Examples
This method can be useful for situations in which the vector is serving as a buffer for other code, particularly over FFI:
use heapless::Vec; use heapless::consts::*; pub fn get_dictionary(&self) -> Option<Vec<u8, U32768>> { // Per the FFI method's docs, "32768 bytes is always enough". let mut dict = Vec::new(); let mut dict_length = 0; // SAFETY: When `deflateGetDictionary` returns `Z_OK`, it holds that: // 1. `dict_length` elements were initialized. // 2. `dict_length` <= the capacity (32_768) // which makes `set_len` safe to call. unsafe { // Make the FFI call... let r = deflateGetDictionary(self.strm, dict.as_mut_ptr(), &mut dict_length); if r == Z_OK { // ...and update the length to what was initialized. dict.set_len(dict_length); Some(dict) } else { None } } }
While the following example is sound, there is a memory leak since
the inner vectors were not freed prior to the set_len
call:
use core::iter::FromIterator; use heapless::Vec; use heapless::consts::*; let mut vec = Vec::<Vec<u8, U3>, U3>::from_iter( [ Vec::from_iter([1, 0, 0].iter().cloned()), Vec::from_iter([0, 1, 0].iter().cloned()), Vec::from_iter([0, 0, 1].iter().cloned()), ] .iter() .cloned() ); // SAFETY: // 1. `old_len..0` is empty so no elements need to be initialized. // 2. `0 <= capacity` always holds whatever `capacity` is. unsafe { vec.set_len(0); }
Normally, here, one would use clear
instead to correctly drop
the contents and thus not leak memory.
pub fn swap_remove(&mut self, index: usize) -> T
[src]
pub fn swap_remove(&mut self, index: usize) -> T
[src]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"]);
pub fn starts_with(&self, needle: &[T]) -> bool where
T: PartialEq<T>,
[src]
pub fn starts_with(&self, needle: &[T]) -> bool where
T: PartialEq<T>,
[src]Returns true
if needle
is a prefix of the Vec.
Always returns true
if needle
is an empty slice.
Examples
use heapless::Vec; use heapless::consts::*; let v: Vec<_, U8> = Vec::from_slice(b"abc").unwrap(); assert_eq!(v.starts_with(b""), true); assert_eq!(v.starts_with(b"ab"), true); assert_eq!(v.starts_with(b"bc"), false);
pub fn ends_with(&self, needle: &[T]) -> bool where
T: PartialEq<T>,
[src]
pub fn ends_with(&self, needle: &[T]) -> bool where
T: PartialEq<T>,
[src]Returns true
if needle
is a suffix of the Vec.
Always returns true
if needle
is an empty slice.
Examples
use heapless::Vec; use heapless::consts::*; let v: Vec<_, U8> = Vec::from_slice(b"abc").unwrap(); assert_eq!(v.ends_with(b""), true); assert_eq!(v.ends_with(b"ab"), false); assert_eq!(v.ends_with(b"bc"), true);
Trait Implementations
impl<'de, N> Deserialize<'de> for Bytes<N> where
N: ArrayLength<u8>,
[src]
impl<'de, N> Deserialize<'de> for Bytes<N> where
N: ArrayLength<u8>,
[src]pub fn deserialize<D>(
deserializer: D
) -> Result<Bytes<N>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
[src]
pub fn deserialize<D>(
deserializer: D
) -> Result<Bytes<N>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl<'a, N> IntoIterator for &'a Bytes<N> where
N: ArrayLength<u8>,
[src]
impl<'a, N> IntoIterator for &'a Bytes<N> where
N: ArrayLength<u8>,
[src]type Item = &'a u8
type Item = &'a u8
The type of the elements being iterated over.
type IntoIter = <&'a [u8] as IntoIterator>::IntoIter
type IntoIter = <&'a [u8] 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]
impl<'a, N> IntoIterator for &'a mut Bytes<N> where
N: ArrayLength<u8>,
[src]type Item = &'a mut u8
type Item = &'a mut u8
The type of the elements being iterated over.
type IntoIter = <&'a mut [u8] as IntoIterator>::IntoIter
type IntoIter = <&'a mut [u8] as IntoIterator>::IntoIter
Which kind of iterator are we turning this into?
impl<N> IntoIterator for Bytes<N> where
N: ArrayLength<u8>,
[src]
impl<N> IntoIterator for Bytes<N> where
N: ArrayLength<u8>,
[src]impl<N, Rhs> PartialOrd<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]pub fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>
[src]
pub fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>
[src]This method returns an ordering between self
and other
values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<N> Serialize for Bytes<N> where
N: ArrayLength<u8>,
[src]
impl<N> Serialize for Bytes<N> where
N: ArrayLength<u8>,
[src]pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
[src]
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
[src]Serialize this value into the given Serde serializer. Read more
impl<N> Eq for Bytes<N> where
N: Eq + ArrayLength<u8>,
[src]
N: Eq + ArrayLength<u8>,
impl<N> StructuralEq for Bytes<N> where
N: ArrayLength<u8>,
[src]
N: ArrayLength<u8>,
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,
<N as ArrayLength<u8>>::ArrayType: Unpin,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,