[][src]Struct static_linkedlist::StaticLinkedListBackingArray

pub struct StaticLinkedListBackingArray<'buf, T> where
    T: Clear
{ /* fields omitted */ }

The backing array for the singly-linked lists. This struct needs to be initialized first before lists can be created.

Methods

impl<'buf, T> StaticLinkedListBackingArray<'buf, T> where
    T: Clear
[src]

pub const fn capacity_for(n: usize) -> usize
[src]

Convenience function calculating the bytes required for an array of n elements of type T plus the list's metadata (i.e. next pointer). Requires the const_fn feature.

Example:

use static_linkedlist::{Clear, StaticLinkedListBackingArray};

struct U32Clear(pub u32);

impl Clear for U32Clear {
   fn clear(&mut self) {
       self.0 = 0;
   }
}

// Reserve memory for 20 instances of U32Clear plus list metadata. This executes at compile time!
const BUF_SIZE: usize = StaticLinkedListBackingArray::<U32Clear>::capacity_for(20);
let mut buf: [u8; BUF_SIZE] = [0; BUF_SIZE];
let mut array = StaticLinkedListBackingArray::<U32Clear>::new(&mut buf).unwrap();

pub fn new(buf: &'buf mut [u8]) -> Result<Self, Error>
[src]

Creates a new backing array for linked lists from the given buf. The second argument bytes must be the size of buf in bytes!

Buffer size

Note that the linked list needs some space for metadata (pointers to the next element). Consequently, for n elements of size s, it does not suffice to allocate s * n bytes! To allocate the exact needed amount of memory, use capacity_for().

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

Returns the backing array's capacity.

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

Returns the remaining space for element sof type T in the array.

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

Returns true if the array is full.

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

Return the number of lists backed by this array.

pub fn new_list(&mut self) -> StaticLinkedList<'buf, T>
[src]

Creates a new StaticLinkedList backed by the memory of this array.

Auto Trait Implementations

impl<'buf, T> !Send for StaticLinkedListBackingArray<'buf, T>

impl<'buf, T> !Sync for StaticLinkedListBackingArray<'buf, T>

Blanket Implementations

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> From for T
[src]

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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