Trait sanakirja::Representable
[−]
[src]
pub trait Representable: Copy + Debug { fn onpage_size(&self) -> u16; unsafe fn write_value(&self, p: *mut u8); unsafe fn read_value(p: *const u8) -> Self; unsafe fn cmp_value<T: LoadPage>(&self, txn: &T, x: Self) -> Ordering; fn alignment() -> Alignment { ... } unsafe fn skip(p: *mut u8) -> *mut u8 { ... } fn drop_value<T, R: Rng>(&self,
_: &mut MutTxn<T>,
_: &mut R)
-> Result<(), Error> { ... } fn page_offset(&self) -> Option<u64> { ... } }
Types that can be stored in a Sanakirja database, as keys or values. Some care must be taken when storing things.
Required Methods
fn onpage_size(&self) -> u16
How much space this value occupies on the page (not counting alignment padding).
unsafe fn write_value(&self, p: *mut u8)
Write this value to a u8 pointer, guaranteed to be a multiple of self.alignment()
.
unsafe fn read_value(p: *const u8) -> Self
Read value from an onpage pointer, guaranteed to be a multiple of self.alignment()
.
unsafe fn cmp_value<T: LoadPage>(&self, txn: &T, x: Self) -> Ordering
Compare a value with an onpage value. The current transaction is sometimes helpful, for instance when the page only stores a pointer to another page.
Provided Methods
fn alignment() -> Alignment
Alignment of this type. Allowed values are 1, 2, 4 and 8.
unsafe fn skip(p: *mut u8) -> *mut u8
First pointer strictly after this value's pointer. The default
implementation is basically p.offset(self.onpage_size() as isize)
, but their might be more efficient implementations in
some cases.
fn drop_value<T, R: Rng>(&self,
_: &mut MutTxn<T>,
_: &mut R)
-> Result<(), Error>
_: &mut MutTxn<T>,
_: &mut R)
-> Result<(), Error>
How to free the pages used by this value. The default implementation doesn't do anything, which is fine for types stored directly on B tree pages.
fn page_offset(&self) -> Option<u64>
If this value is an offset to another page at offset offset
,
return Some(offset)
. Return None
else.
Implementors
impl Representable for UnsafeValue
impl Representable for u64
impl<K: Representable, V: Representable> Representable for Db<K, V>