StaticBuf

Struct StaticBuf 

Source
pub struct StaticBuf<T: Copy, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> { /* private fields */ }
Expand description

Static byte buffer. StaticBuf<[u8; 16]> can store a [u8] array from 0-16 bytes for example. Unlike other static buffers, this does NOT reallocate if you out grow the internal buffer. If you try to request more bytes than its able to store, it will panic.

Implementations§

Source§

impl<T: Copy, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> StaticBuf<T, ArrayBuf>

Source

pub fn new() -> Self

Source

pub fn max_size() -> usize

Returns the maximum size the StaticBuf can hold.

§Examples
use btle::bytes::StaticBuf;
assert_eq!(StaticBuf::<u8, [u8; 10]>::max_size(), 10);
assert_eq!(StaticBuf::<u8, [u8; 23]>::max_size(), 23);
Source

pub fn space_left(&self) -> usize

Returns the space left in Ts (not bytes) in the StaticBuf. Simply (capacity - length).

Source

pub fn resize(&mut self, new_size: usize)

Resizes the StaticBuf by settings self.len to new_size if new_size <= Self::max_size(). This is only a single variable change and WILL NOT zero or change any of the buffers bytes.

§Panics

Panics if the new size is greater than max_size (new_size > Self::max_size()).

§Examples
use btle::bytes::{StaticBuf, Storage};
let mut buf = StaticBuf::<u8, [u8; 10]>::with_size(10);
assert_eq!(buf.len(), 10);
assert_eq!(buf[9], 0);
buf[9] = 0xFF;
buf.resize(1);
assert_eq!(buf.len(), 1);
buf.resize(10);
assert_eq!(buf[9], 0xFF);
Source

pub fn append_slice(&mut self, slice: &[T])

Appends the slice onto the end of the StaticBuf.

§Panics

Panics if appending the slice would overflow the StaticBuf (not enough space).

Trait Implementations§

Source§

impl<T: Copy, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> AsMut<[T]> for StaticBuf<T, ArrayBuf>

Source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: Copy, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> AsRef<[T]> for StaticBuf<T, ArrayBuf>

Source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone + Copy, ArrayBuf: Clone + AsRef<[T]> + AsMut<[T]> + Default + Copy> Clone for StaticBuf<T, ArrayBuf>

Source§

fn clone(&self) -> StaticBuf<T, ArrayBuf>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Copy, ArrayBuf: Debug + AsRef<[T]> + AsMut<[T]> + Default + Copy> Debug for StaticBuf<T, ArrayBuf>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + Copy, ArrayBuf: Default + AsRef<[T]> + AsMut<[T]> + Default + Copy> Default for StaticBuf<T, ArrayBuf>

Source§

fn default() -> StaticBuf<T, ArrayBuf>

Returns the “default value” for a type. Read more
Source§

impl<T: Hash + Copy, ArrayBuf: Hash + AsRef<[T]> + AsMut<[T]> + Default + Copy> Hash for StaticBuf<T, ArrayBuf>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Copy, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> Index<RangeFull> for StaticBuf<T, ArrayBuf>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, _index: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: Copy + Default, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> Index<usize> for StaticBuf<T, ArrayBuf>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: Copy, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> IndexMut<RangeFull> for StaticBuf<T, ArrayBuf>

Source§

fn index_mut(&mut self, _index: RangeFull) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: Copy + Default, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> IndexMut<usize> for StaticBuf<T, ArrayBuf>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: Ord + Copy, ArrayBuf: Ord + AsRef<[T]> + AsMut<[T]> + Default + Copy> Ord for StaticBuf<T, ArrayBuf>

Source§

fn cmp(&self, other: &StaticBuf<T, ArrayBuf>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq + Copy, ArrayBuf: PartialEq + AsRef<[T]> + AsMut<[T]> + Default + Copy> PartialEq for StaticBuf<T, ArrayBuf>

Source§

fn eq(&self, other: &StaticBuf<T, ArrayBuf>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd + Copy, ArrayBuf: PartialOrd + AsRef<[T]> + AsMut<[T]> + Default + Copy> PartialOrd for StaticBuf<T, ArrayBuf>

Source§

fn partial_cmp(&self, other: &StaticBuf<T, ArrayBuf>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Copy + Unpin + Default, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy + Unpin> Storage<T> for StaticBuf<T, ArrayBuf>

Source§

fn with_size(size: usize) -> Self
where Self: Sized,

Source§

fn max_len() -> usize

Source§

fn len(&self) -> usize

Source§

fn from_slice(buf: &[T]) -> Self
where Self: Sized,

Source§

fn space_left(&self) -> usize

Source§

impl<T: Copy + Copy, ArrayBuf: Copy + AsRef<[T]> + AsMut<[T]> + Default + Copy> Copy for StaticBuf<T, ArrayBuf>

Source§

impl<T: Eq + Copy, ArrayBuf: Eq + AsRef<[T]> + AsMut<[T]> + Default + Copy> Eq for StaticBuf<T, ArrayBuf>

Source§

impl<T: Copy, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> StructuralPartialEq for StaticBuf<T, ArrayBuf>

Auto Trait Implementations§

§

impl<T, ArrayBuf> Freeze for StaticBuf<T, ArrayBuf>
where ArrayBuf: Freeze,

§

impl<T, ArrayBuf> RefUnwindSafe for StaticBuf<T, ArrayBuf>
where ArrayBuf: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, ArrayBuf> Send for StaticBuf<T, ArrayBuf>
where ArrayBuf: Send, T: Send,

§

impl<T, ArrayBuf> Sync for StaticBuf<T, ArrayBuf>
where ArrayBuf: Sync, T: Sync,

§

impl<T, ArrayBuf> Unpin for StaticBuf<T, ArrayBuf>
where ArrayBuf: Unpin, T: Unpin,

§

impl<T, ArrayBuf> UnwindSafe for StaticBuf<T, ArrayBuf>
where ArrayBuf: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.