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>

source

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.

source

pub unsafe fn unchecked_from_header(header: *const RecordHeader) -> Self

Constructs a new reference to the DBN record.

Safety

header must point to a valid DBN record.

source

pub fn header(&self) -> &RecordHeader

Returns a reference to the RecordHeader of the referenced record.

source

pub fn has<T: HasRType>(&self) -> bool

Returns true if the object points to a record of type T.

source

pub fn record_size(&self) -> usize

Returns the size of the record in bytes.

source

pub fn rtype(&self) -> Result<RType>

Tries to convert the raw rtype into an enum which is useful for exhaustive pattern matching.

Errors

This function returns an error if the rtype field does not contain a valid, known RType.

source

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.

source

pub unsafe fn get_unchecked<T: HasRType>(&self) -> &T

Returns a reference to the underlying record of type T without checking if this object references a record of type T.

For a safe alternative, see get().

Safety

The caller needs to validate this object points to a T.

Trait Implementations§

source§

impl<'a> AsRef<[u8]> for RecordRef<'a>

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a> Clone for RecordRef<'a>

source§

fn clone(&self) -> RecordRef<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for RecordRef<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Send for RecordRef<'_>

source§

impl Sync for RecordRef<'_>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for RecordRef<'a>

§

impl<'a> Unpin for RecordRef<'a>

§

impl<'a> UnwindSafe for RecordRef<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Ungil for Twhere T: Send,