Skip to main content

TupleSerdeBinding

Struct TupleSerdeBinding 

Source
pub struct TupleSerdeBinding<K, V> { /* private fields */ }
Expand description

Entity binding that uses sort-preserving tuple encoding for keys and serde binary encoding for data.

The key type K must implement SortKey, which guarantees that the byte-wise order of encoded keys matches the Ord order of the original values. This makes range scans, get_next, get_prev, and sorted map operations correct without requiring a custom comparator.

The entity type V is split into a key K and a data payload V via user-provided extraction functions.

§Examples

use serde::{Serialize, Deserialize};
use noxu_bind::serial::tuple_serde_binding::TupleSerdeBinding;
use noxu_bind::entry_binding::EntityBinding;
use noxu_db::DatabaseEntry;

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
struct Employee {
    id: u64,
    name: String,
    department: String,
}

let binding = TupleSerdeBinding::<u64, Employee>::new(
    |emp: &Employee| emp.id,
    |key: u64, data: Employee| data,
);

Implementations§

Source§

impl<K, V> TupleSerdeBinding<K, V>

Source

pub fn new<FKey, FCreate>(key_extractor: FKey, entity_creator: FCreate) -> Self
where FKey: Fn(&V) -> K + Send + Sync + 'static, FCreate: Fn(K, V) -> V + Send + Sync + 'static,

Creates a new composite binding with the given key extractor and entity creator.

  • key_extractor: extracts the sort key from an entity value.
  • entity_creator: reconstructs the entity from key and data.

Trait Implementations§

Source§

impl<K, V> Debug for TupleSerdeBinding<K, V>

Source§

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

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

impl<K, V> EntityBinding<V> for TupleSerdeBinding<K, V>

Source§

fn entry_to_object( &self, key: &DatabaseEntry, data: &DatabaseEntry, ) -> Result<V>

Converts key and data entries to an entity object. Read more
Source§

fn object_to_key(&self, object: &V, key: &mut DatabaseEntry) -> Result<()>

Extracts the key from an entity object and writes it to a DatabaseEntry. Read more
Source§

fn object_to_data(&self, object: &V, data: &mut DatabaseEntry) -> Result<()>

Extracts the data from an entity object and writes it to a DatabaseEntry. Read more

Auto Trait Implementations§

§

impl<K, V> !RefUnwindSafe for TupleSerdeBinding<K, V>

§

impl<K, V> !UnwindSafe for TupleSerdeBinding<K, V>

§

impl<K, V> Freeze for TupleSerdeBinding<K, V>

§

impl<K, V> Send for TupleSerdeBinding<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for TupleSerdeBinding<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for TupleSerdeBinding<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnsafeUnpin for TupleSerdeBinding<K, V>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.