Struct dbn::record_ref::RecordRef
source · pub struct RecordRef<'a> { /* private fields */ }Expand description
A wrapper around a non-owning immutable reference to a DBN record. This wrapper allows for mixing of record types and schemas, and runtime record polymorphism.
Implementations§
source§impl<'a> RecordRef<'a>
impl<'a> RecordRef<'a>
sourcepub unsafe fn new(buffer: &'a [u8]) -> Self
pub unsafe fn new(buffer: &'a [u8]) -> Self
Constructs a new reference to the DBN record in buffer.
Safety
buffer should begin with a RecordHeader and contain a type implementing
HasRType.
sourcepub unsafe fn unchecked_from_header(header: *const RecordHeader) -> Self
pub unsafe fn unchecked_from_header(header: *const RecordHeader) -> Self
sourcepub fn header(&self) -> &RecordHeader
pub fn header(&self) -> &RecordHeader
Returns a reference to the RecordHeader of the referenced record.
sourcepub fn has<T: HasRType>(&self) -> bool
pub fn has<T: HasRType>(&self) -> bool
Returns true if the object points to a record of type T.
sourcepub fn record_size(&self) -> usize
pub fn record_size(&self) -> usize
Returns the size of the record in bytes.
sourcepub fn get<T: HasRType>(&self) -> Option<&'a T>
pub fn get<T: HasRType>(&self) -> Option<&'a T>
Returns a reference to the underlying record of type T or None if it points
to another record type.
Note: for safety, this method calls has::<T>(). To avoid a
duplicate check, use get_unchecked().
Panics
This function will panic if the rtype indicates it’s of type T but the encoded
length of the record is less than the size of T.