Struct tarantool::tuple::KeyDef

source ·
pub struct KeyDef { /* private fields */ }
Expand description

An object which describes how to extract a key for a given tarantool index from a tuple. Basically it contains information the parts of the key, specifically location of the parts within the tuple, their types, their nullability and collation.

Can be used to

You can construct one of these from an explicit list of key part definitions using Self::new, or automtically from an index’s metadata like so:

let space = Space::find("some_space").unwrap();
let index = space.index("some_index").unwrap();
let meta = index.meta().unwrap();
let key_def: KeyDef = meta.to_key_def();

Implementations§

source§

impl KeyDef

source

pub fn new<'a>( parts: impl IntoIterator<Item = &'a KeyDefPart<'a>> ) -> Result<Self>

Create key definition with key fields with passed typed on passed positions. May be used for tuple format creation and/or tuple comparison.

  • items - array with key field identifiers and key field types (see FieldType)
source

pub fn compare(&self, tuple_a: &Tuple, tuple_b: &Tuple) -> Ordering

Compare tuples using the key definition.

  • tuple_a - first tuple
  • tuple_b - second tuple

Returns:

  • Ordering::Equal if key_fields(tuple_a) == key_fields(tuple_b)
  • Ordering::Less if key_fields(tuple_a) < key_fields(tuple_b)
  • Ordering::Greater if key_fields(tuple_a) > key_fields(tuple_b)
source

pub fn compare_with_key<K>(&self, tuple: &Tuple, key: &K) -> Ordering
where K: ToTupleBuffer + ?Sized,

Compare tuple with key using the key definition.

  • tuple - tuple
  • key - key with MessagePack array header

Returns:

  • Ordering::Equal if key_fields(tuple) == parts(key)
  • Ordering::Less if key_fields(tuple) < parts(key)
  • Ordering::Greater if key_fields(tuple) > parts(key)
source

pub fn validate_tuple(&self, tuple: &Tuple) -> Result<()>

Checks if tuple satisfies the key definition’s format, i.e. do the tuple’s fields described the self’s key parts have the same types. Note that the tuple may still not satisfy the full format of the space, this function only checks if it contains a part which could be used as a key of an index.

There’s currently no good way of checking if the tuple satisfies the format of the space other than trying to insert into that space.

This function is used internally by Self::extract_key to check if it’s safe to extract the key described by this KeyDef from a given tuple.

source

pub fn extract_key(&self, tuple: &Tuple) -> Result<TupleBuffer>

Extracts the key described by this KeyDef from tuple. Returns an error if tuple doesn’t satisfy this KeyDef.

source

pub unsafe fn extract_key_raw<'box_region>( &self, tuple: &Tuple, multikey_idx: i32 ) -> Result<&'box_region [u8]>

Extracts the key described by this KeyDef from tuple.

TODO: what is multikey_idx? Pass a -1 as the default value.

Returns an error in case memory runs out.

Safety

tuple must satisfy the key definition’s format. Use Self::extract_key if you want the tuple to be validated automatically, or use Self::validate_tuple to validate the tuple explicitly.

Trait Implementations§

source§

impl Debug for KeyDef

source§

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

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

impl Drop for KeyDef

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl TryFrom<&Metadata<'_>> for KeyDef

§

type Error = FieldMustBeNumber

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

fn try_from(meta: &Metadata<'_>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl RefUnwindSafe for KeyDef

§

impl !Send for KeyDef

§

impl !Sync for KeyDef

§

impl Unpin for KeyDef

§

impl UnwindSafe for KeyDef

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

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.