Skip to main content

Comparator

Struct Comparator 

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

A key ordering, owned by Rust and shareable with anything that needs one.

RocksDB never takes ownership of a comparator: Options, WriteBatchWithIndex and the rest all keep a borrowed pointer to it. Wrap it in an Arc and hand out clones so it outlives every user, which is what Options::set_comparator does internally.

Implementations§

Source§

impl Comparator

Source

pub fn new( name: impl CStrLike, compare_fn: Box<dyn Fn(&[u8], &[u8]) -> Ordering + Send + Sync>, ) -> Self

Builds a comparator from a total order over keys.

name is persisted in the SST files. Changing the ordering without changing the name gives RocksDB no way to notice, and it will read the old files with the new ordering, so pick a new name whenever the order changes.

§Panics

Panics if name contains an interior nul byte.

Source

pub fn with_ts( name: impl CStrLike, timestamp_size: usize, compare_fn: Box<dyn Fn(&[u8], &[u8]) -> Ordering + Send + Sync>, compare_ts_fn: Box<dyn Fn(&[u8], &[u8]) -> Ordering + Send + Sync>, compare_without_ts_fn: Box<dyn Fn(&[u8], bool, &[u8], bool) -> Ordering + Send + Sync>, ) -> Self

Builds a comparator for a column family that uses user-defined timestamps.

timestamp_size is the fixed width of the timestamp suffix on every key. compare_fn orders whole keys including the timestamp, compare_ts_fn orders two bare timestamps, and compare_without_ts_fn orders keys ignoring their timestamps. See the RocksDB user-defined timestamp docs.

§Panics

Panics if name contains an interior nul byte.

Trait Implementations§

Source§

impl Drop for Comparator

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Comparator

Source§

impl Sync for Comparator

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.