Skip to main content

DatabaseEntry

Struct DatabaseEntry 

Source
pub struct DatabaseEntry { /* private fields */ }
Expand description

Encodes database key and data items as byte arrays.

Both key and data items are represented by DatabaseEntry objects. Key and data byte arrays may refer to arrays of zero length up to arrays of essentially unlimited length.

Internally uses bytes::Bytes so that clone() is O(1) (reference-count increment) and from_vec / set_data_vec are zero-copy.

Implementations§

Source§

impl DatabaseEntry

Source

pub fn new() -> Self

Creates an empty DatabaseEntry.

Source

pub fn from_bytes(data: &[u8]) -> Self

Creates a DatabaseEntry from a byte slice (copies the slice).

Alias: from_data is also available.

Source

pub fn from_vec(data: Vec<u8>) -> Self

Creates a DatabaseEntry from an owned Vec<u8> — zero-copy.

Source

pub fn from_bytes_ref(data: Bytes) -> Self

Creates a DatabaseEntry from an existing Bytes — zero-copy.

Source

pub fn get_data(&self) -> Option<&[u8]>

Gets a reference to the data.

Returns None if the entry is empty, otherwise returns a slice from offset to offset+size.

Source

pub fn set_data(&mut self, data: &[u8])

Sets the data from a byte slice (copies the slice).

Source

pub fn set_data_vec(&mut self, data: Vec<u8>)

Sets the data from an owned Vec<u8> — zero-copy.

Source

pub fn set_data_bytes(&mut self, data: Bytes)

Sets the data from an existing Bytes — zero-copy.

Source

pub fn from_data(data: &[u8]) -> Self

Creates a DatabaseEntry from a byte slice.

Alias for from_bytes.

Source

pub fn data(&self) -> &[u8]

Gets the data as a byte slice, returning an empty slice if no data.

Convenience method that unwraps the Option from get_data().

Source

pub fn get_size(&self) -> usize

Gets the size of the data.

Source

pub fn set_offset(&mut self, offset: usize)

Sets the offset within the data array.

Source

pub fn get_offset(&self) -> usize

Gets the offset within the data array.

Source

pub fn set_size(&mut self, size: usize)

Sets the size of the data.

Source

pub fn set_partial(&mut self, offset: usize, length: usize, partial: bool)

Configures this entry as a partial entry.

Partial entries are used to read or write only a portion of a record.

Source

pub fn is_partial(&self) -> bool

Returns whether this is a partial entry.

Source

pub fn get_partial_offset(&self) -> usize

Gets the partial offset.

Source

pub fn get_partial_length(&self) -> usize

Gets the partial length.

Source

pub fn clear(&mut self)

Clears the entry, removing all data.

Source

pub fn is_empty(&self) -> bool

Returns true if the entry is empty (has no data).

Trait Implementations§

Source§

impl Clone for DatabaseEntry

Source§

fn clone(&self) -> DatabaseEntry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DatabaseEntry

Source§

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

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

impl Default for DatabaseEntry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&[u8]> for DatabaseEntry

Source§

fn from(data: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for DatabaseEntry

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for DatabaseEntry

Source§

fn from(data: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<String> for DatabaseEntry

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for DatabaseEntry

Source§

fn from(data: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for DatabaseEntry

Source§

fn eq(&self, other: &DatabaseEntry) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for DatabaseEntry

Source§

impl StructuralPartialEq for DatabaseEntry

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more