Trait kwap_msg::Collection[][src]

pub trait Collection<T>: Default + GetSize + Reserve + Extend<T> + FromIterator<T> + IntoIterator<Item = T> where
    for<'a> &'a Self: IntoIterator<Item = &'a T>, 
{ }
Expand description

Any collection may be used to store bytes in CoAP Messages :)

Provided implementations

Notably, not heapless::ArrayVec or arrayvec::ArrayVec. An important usecase is Extending the collection, and the performance of heapless and arrayvec’s Extend implementations are notably worse than tinyvec.

tinyvec also has the added bonus of being 100% unsafe-code-free, meaning if you choose tinyvec you eliminate the possibility of memory defects and UB.

Requirements

  • Default for creating the collection
  • Extend for mutating and adding onto the collection (1 or more elements)
  • Reserve for reserving space ahead of time
  • GetSize for bound checks, empty checks, and accessing the length
  • FromIterator for collecting into the collection
  • IntoIterator for:
    • iterating and destroying the collection
    • for iterating over references to items in the collection

Stupid where clause

where for<'a> &'a Self: IntoIterator<Item = &'a T> is necessary to fold in the idea of “A reference (of any arbitrary lifetime 'a) to a Collection must support iterating over references ('a) of its elements.”

A side-effect of this where clause is that because it’s not a trait bound, it must be propagated to every bound that requires a Collection.

Less than ideal, but far preferable to coupling tightly to a particular collection and maintaining separate alloc and non-alloc implementations.

Implementations on Foreign Types

Implementors