Struct tikv_client::Key[][src]

#[repr(transparent)]pub struct Key(pub(super) Vec<u8>);

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


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:


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.


impl Key[src]

pub const EMPTY: Self[src]

The empty key.

pub fn is_empty(&self) -> bool[src]

Return whether the key is empty.

pub(super) fn zero_terminated(&self) -> bool[src]

Return whether the last byte of key is 0.

pub(super) fn push_zero(&mut self)[src]

Push a zero to the end of the key.

Extending a zero makes the new key the smallest key that is greater than than the original one, i.e. the succeeder.

pub(super) fn into_lower_bound(self) -> Bound<Key>[src]

Convert the key to a lower bound. The key is treated as inclusive.

pub(super) fn into_upper_bound(self) -> Bound<Key>[src]

Convert the key to an upper bound. The key is treated as exclusive.

pub fn to_encoded(&self) -> Key[src]

Return the MVCC-encoded representation of the key.

Trait Implementations

impl AsRef<Key> for Key[src]

impl AsRef<Key> for KvPair[src]

impl Clone for Key[src]

impl Debug for Key[src]

impl Default for Key[src]

impl Eq for Key[src]

impl<'a> From<&'a Vec<u8, Global>> for &'a Key[src]

impl From<KvPair> for Key[src]

impl From<String> for Key[src]

impl From<Vec<u8, Global>> for Key[src]

impl Hash for Key[src]

impl Ord for Key[src]

impl PartialEq<Key> for Key[src]

impl PartialOrd<Key> for Key[src]

impl RangeBounds<Key> for BoundRange[src]

impl StructuralEq for Key[src]

impl StructuralPartialEq for Key[src]

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

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

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

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

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

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

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.

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