CustomBorrow

Trait CustomBorrow 

Source
pub trait CustomBorrow<'a, T, L> {
    // Required methods
    fn custom_borrow(&'a mut self, layout: L) -> T;
    unsafe fn extract_layout(&self) -> L;
}
Expand description

A trait that allows for custom implementation of borrow given the necessary information This is useful for record structs that have dynamic size

Required Methods§

Source

fn custom_borrow(&'a mut self, layout: L) -> T

Source

unsafe fn extract_layout(&self) -> L

Given &self as a valid starting pointer of a reference that has already been previously allocated and written to, extracts and returns the corresponding layout. This must work even if T is not sized.

§Safety
  • &self must be a valid starting pointer on which custom_borrow has already been called
  • The data underlying &self has already been written to and is self-describing, so layout can be extracted

Implementations on Foreign Types§

Source§

impl<'a> CustomBorrow<'a, AccessRecordMut<'a>, AccessLayout> for [u8]

Source§

fn custom_borrow(&'a mut self, layout: AccessLayout) -> AccessRecordMut<'a>

Source§

unsafe fn extract_layout(&self) -> AccessLayout

Source§

impl<'a, T: Sized, L: Default> CustomBorrow<'a, &'a mut T, L> for [u8]
where [u8]: BorrowMut<T>,

If a struct implements BorrowMut<T>, then the same implementation can be used for CustomBorrow::custom_borrow with any layout

Source§

fn custom_borrow(&'a mut self, _layout: L) -> &'a mut T

Source§

unsafe fn extract_layout(&self) -> L

Implementors§