Struct tikv_client::Key

source ·
pub struct Key(/* private fields */);
Expand description

The key part of a key/value pair.

In TiKV, keys are an ordered sequence of bytes. This has an advantage over choosing String as valid UTF-8 is not required. This means that the user is permitted to store any data they wish, as long as it can be represented by bytes. (Which is to say, pretty much anything!)

This type wraps around an owned value, so it should be treated it like String or Vec<u8>.

Examples

use tikv_client::Key;

let static_str: &'static str = "TiKV";
let from_static_str = Key::from(static_str.to_owned());

let string: String = String::from(static_str);
let from_string = Key::from(string);
assert_eq!(from_static_str, from_string);

let vec: Vec<u8> = static_str.as_bytes().to_vec();
let from_vec = Key::from(vec);
assert_eq!(from_static_str, from_vec);

let bytes = static_str.as_bytes().to_vec();
let from_bytes = Key::from(bytes);
assert_eq!(from_static_str, from_bytes);

While .into() is usually sufficient for obtaining the buffer itself, sometimes type inference isn’t able to determine the correct type. Notably in the assert_eq!() and == cases. In these cases using the fully-qualified-syntax is useful:

Examples

use tikv_client::Key;

let buf = "TiKV".as_bytes().to_owned();
let key = Key::from(buf.clone());
assert_eq!(Into::<Vec<u8>>::into(key), buf);

Many functions which accept a Key accept an Into<Key>, which means all of the above types can be passed directly to those functions.

Implementations§

source§

impl Key

source

pub const EMPTY: Self = _

The empty key.

source

pub fn is_empty(&self) -> bool

Return whether the key is empty.

source

pub fn to_encoded(&self) -> Key

Return the MVCC-encoded representation of the key.

source

pub fn len(&self) -> usize

Trait Implementations§

source§

impl AsRef<Key> for Key

source§

fn as_ref(&self) -> &Key

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

impl AsRef<Key> for KvPair

source§

fn as_ref(&self) -> &Key

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

impl AsRef<Key> for Vec<u8>

source§

fn as_ref(&self) -> &Key

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

impl Clone for Key

source§

fn clone(&self) -> Key

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 Debug for Key

source§

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

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

impl Default for Key

source§

fn default() -> Key

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

impl<'a> From<&'a Key> for &'a [u8]

source§

fn from(key: &'a Key) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a Vec<u8>> for &'a Key

source§

fn from(key: &'a Vec<u8>) -> Self

Converts to this type from the input type.
source§

impl From<Key> for Vec<u8>

source§

fn from(key: Key) -> Self

Converts to this type from the input type.
source§

impl From<KvPair> for Key

source§

fn from(pair: KvPair) -> Self

Converts to this type from the input type.
source§

impl From<String> for Key

source§

fn from(v: String) -> Key

Converts to this type from the input type.
source§

impl From<Vec<u8>> for Key

source§

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

Converts to this type from the input type.
source§

impl Hash for Key

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Key

source§

fn cmp(&self, other: &Key) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Key

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Key

source§

fn partial_cmp(&self, other: &Key) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PessimisticLock for Key

source§

fn key(self) -> Key

source§

fn assertion(&self) -> Assertion

source§

impl RangeBounds<Key> for BoundRange

source§

fn start_bound(&self) -> Bound<&Key>

Start index bound. Read more
source§

fn end_bound(&self) -> Bound<&Key>

End index bound. Read more
1.35.0 · source§

fn contains<U>(&self, item: &U) -> boolwhere T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
source§

impl Eq for Key

source§

impl StructuralEq for Key

source§

impl StructuralPartialEq for Key

Auto Trait Implementations§

§

impl RefUnwindSafe for Key

§

impl Send for Key

§

impl Sync for Key

§

impl Unpin for Key

§

impl UnwindSafe for Key

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
§

impl<Q, K> Comparable<K> for Qwhere Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Qwhere 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.
§

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

§

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

Checks if this value is equivalent to the given key. Read more
§

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

§

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.

§

impl<T> FromRef<T> for Twhere T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

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

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

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

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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