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§
Trait Implementations§
source§impl Ord for Key
impl Ord for Key
source§impl PartialOrd for Key
impl PartialOrd for Key
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PessimisticLock for Key
impl PessimisticLock for Key
source§impl RangeBounds<Key> for BoundRange
impl RangeBounds<Key> for BoundRange
1.35.0 · source§fn contains<U>(&self, item: &U) -> boolwhere
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
fn contains<U>(&self, item: &U) -> boolwhere T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,
impl Eq for Key
impl StructuralEq for Key
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> 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<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§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