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 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 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
.
sourcepub fn as_enum(&self) -> Result<RecordRefEnum<'_>>
pub fn as_enum(&self) -> Result<RecordRefEnum<'_>>
Returns a native Rust enum with a variant for each record type. This allows for
pattern match
ing.
§Errors
This function returns a conversion error if the rtype does not correspond with any known DBN record type.
Trait Implementations§
source§impl<'a> From<&'a RecordEnum> for RecordRef<'a>
impl<'a> From<&'a RecordEnum> for RecordRef<'a>
source§fn from(rec_enum: &'a RecordEnum) -> Self
fn from(rec_enum: &'a RecordEnum) -> Self
source§impl<'a> From<RecordRefEnum<'a>> for RecordRef<'a>
impl<'a> From<RecordRefEnum<'a>> for RecordRef<'a>
source§fn from(rec_enum: RecordRefEnum<'a>) -> Self
fn from(rec_enum: RecordRefEnum<'a>) -> Self
source§impl<'a> Record for RecordRef<'a>
impl<'a> Record for RecordRef<'a>
source§fn header(&self) -> &'a RecordHeader
fn header(&self) -> &'a RecordHeader
RecordHeader
that comes at the beginning of all
record types.source§fn raw_index_ts(&self) -> u64
fn raw_index_ts(&self) -> u64
source§fn record_size(&self) -> usize
fn record_size(&self) -> usize
source§fn rtype(&self) -> Result<RType>
fn rtype(&self) -> Result<RType>
source§fn publisher(&self) -> Result<Publisher>
fn publisher(&self) -> Result<Publisher>
publisher_id
into an enum which is useful for
exhaustive pattern matching. Read moresource§fn index_ts(&self) -> Option<OffsetDateTime>
fn index_ts(&self) -> Option<OffsetDateTime>
None
if the primary
timestamp contains the sentinel value for a null timestamp. Read moresource§fn index_date(&self) -> Option<Date>
fn index_date(&self) -> Option<Date>
index_ts()
). Returns None
if the primary timestamp contains the
sentinel value for a null timestamp.