[][src]Struct kul_core::parser::premade::SliceDatumAllocator

pub struct SliceDatumAllocator<'a, TT, ET> { /* fields omitted */ }

A DatumAllocator for generic Datum types which simplistically allocates Datum values from a contiguous mutable slice of them by supplying mutable borrows of them. Once a Datum element has been allocated, it is not reused if dropped.

This is useful for either or both of:

  • Allocating from stack arrays in constrained environments without heap allocation.

  • Limiting the memory consumed by parsing, e.g. to prevent D.o.S. attacks. Heap-allocated arrays/slices could be used for this.

Allocated elements are not reused if dropped because that would require implementing Drop for the element type which would prevent being able to use basic arrays/slices (because the Datum elements reference each other with the same lifetime, and this only works for element types without Drop). To reuse a slice, a new allocator instance can be constructed with it again, once the prior parsing and borrows of the elements are finished.

Methods

impl<'a, TT, ET> SliceDatumAllocator<'a, TT, ET> where
    TT: Text
[src]

pub fn new(slice: &'a mut [MutRefDatum<'a, TT, ET>]) -> Self[src]

Given a mutable slice of Datums of our type, make a new allocator from it.

pub fn unused(self) -> Option<&'a mut [MutRefDatum<'a, TT, ET>]>[src]

Can be used to regain control of the borrow of the unused rest of the slice, so that it can be used for something else if desired.

Trait Implementations

impl<'a, TT, ET> DatumAllocator for SliceDatumAllocator<'a, TT, ET> where
    TT: Text
[src]

type TT = TT

The Text type for our Datum type. It should also implement TextConcat<Self> so it supports concatenation which the parsing requires. Read more

type ET = ET

The "extra" type for our Datum type.

type DR = DatumMutRef<'a, Self::TT, Self::ET>

The type of references to Datums yielded by our parsing. Read more

impl<'a, TT: Debug, ET: Debug> Debug for SliceDatumAllocator<'a, TT, ET>[src]

Auto Trait Implementations

impl<'a, TT, ET> Send for SliceDatumAllocator<'a, TT, ET> where
    ET: Send,
    TT: Send

impl<'a, TT, ET> Sync for SliceDatumAllocator<'a, TT, ET> where
    ET: Sync,
    TT: Sync

Blanket Implementations

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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]