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§
Trait Implementations§
Source§impl EncodeKeyspace for Key
impl EncodeKeyspace for Key
fn encode_keyspace(self, keyspace: Keyspace, key_mode: KeyMode) -> Self
Source§impl Ord for Key
impl Ord for Key
Source§impl PartialOrd for Key
impl PartialOrd for Key
Source§impl PessimisticLock for Key
impl PessimisticLock for Key
Source§impl RangeBounds<Key> for BoundRange
impl RangeBounds<Key> for BoundRange
Source§impl TruncateKeyspace for Key
impl TruncateKeyspace for Key
fn truncate_keyspace(self, keyspace: Keyspace) -> Self
impl Eq for Key
impl StructuralPartialEq for Key
Auto Trait Implementations§
impl Freeze for Key
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request