[−][src]Struct kul_core::parser::premade::SliceDatumAllocator
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]
TT: Text,
pub fn new(slice: &'a mut [MutRefDatum<'a, TT, ET>]) -> Self
[src]
Given a mutable slice of Datum
s 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]
TT: Text,
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 Datum
s yielded by our parsing. Read more
fn new_datum(
&mut self,
from: MutRefDatum<'a, Self::TT, Self::ET>
) -> Result<Self::DR, AllocError>
[src]
&mut self,
from: MutRefDatum<'a, Self::TT, Self::ET>
) -> Result<Self::DR, AllocError>
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,
ET: Send,
TT: Send,
impl<'a, TT, ET> Sync for SliceDatumAllocator<'a, TT, ET> where
ET: Sync,
TT: Sync,
ET: Sync,
TT: Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,