pub struct RawGetter { /* private fields */ }Expand description
A raw getter for a container of items.
The getter basically provides RawGetter::get method for random access,
but you can register sequential access function through
RawGetter::with_iter. Then you can call RawGetter::iter for
sequential access.
Sequential access would be way faster than random access due to its cache friendly access pattern, so it’s recommended to perfer it over random access as much as possible.
Implementations§
Source§impl RawGetter
impl RawGetter
Sourcepub const unsafe fn new(
this: NonNull<u8>,
len: usize,
fn_get: unsafe fn(this: NonNull<u8>, index: usize) -> NonNull<u8>,
) -> Self
pub const unsafe fn new( this: NonNull<u8>, len: usize, fn_get: unsafe fn(this: NonNull<u8>, index: usize) -> NonNull<u8>, ) -> Self
Creates a new RawGetter from raw parts.
- this - A pointer to a container.
- len - Number of items of the container.
- fn_get - A function that returns pointer to an item for an item index.
§Safety
Caller must guarantee that the created getter must have valid access to the given pointer while it is in use.
Sourcepub const fn with_iter(
self,
fn_iter: unsafe fn(this: NonNull<u8>) -> FlatRawIter,
) -> Self
pub const fn with_iter( self, fn_iter: unsafe fn(this: NonNull<u8>) -> FlatRawIter, ) -> Self
Registers the given function to the raw getter.
- fn_iter - A function pointer for generating sequential access iterator.
Sourcepub fn get(&self, index: usize) -> Option<NonNull<u8>>
pub fn get(&self, index: usize) -> Option<NonNull<u8>>
Returns a type-erased pointer to an item of the associated container.
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> NonNull<u8>
pub unsafe fn get_unchecked(&self, index: usize) -> NonNull<u8>
Returns a type-erased pointer to an item of the associated container.
§Safety
Undefined behavior if the given index is out of bounds.
Sourcepub fn iter(&self) -> FlatRawIter ⓘ
pub fn iter(&self) -> FlatRawIter ⓘ
Returns a sequential access iterator for the associated container.
Make sure that you have registered a function through
RawGetter::with_iter.
§Panics
Panics if iterator geneartion function have not registered yet.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RawGetter
impl RefUnwindSafe for RawGetter
impl Send for RawGetter
impl Sync for RawGetter
impl Unpin for RawGetter
impl UnwindSafe for RawGetter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more