Struct tikv_client::BoundRange
source · pub struct BoundRange {
pub from: Bound<Key>,
pub to: Bound<Key>,
}
Expand description
A struct for expressing ranges. This type is semi-opaque and is not really meant for users to
deal with directly. Most functions which operate on ranges will accept any types which
implement Into<BoundRange>
.
In TiKV, keys are an ordered sequence of bytes. This means we can have ranges over those
bytes. Eg 001
is before 010
.
Minimum key: there is the minimum key: empty key. So a range may not be unbounded below.
The unbounded lower bound in a Range
will be converted to an empty key.
Maximum key: There is no limit of the maximum key. When an empty key is used as the upper bound, it means upper unbounded.
The unbounded upper bound in a Range
. The range covering all keys is just Key::EMPTY..
.
But, you should not need to worry about all this: Most functions which operate
on ranges will accept any types which implement Into<BoundRange>
.
Common range types like a..b
, a..=b
has implemented Into<BoundRange>
where a
and b
impl Into<Key>
. You can implement Into<BoundRange>
for your own types by using try_from
.
It means all of the following types in the example can be passed directly to those functions.
§Examples
let explict_range: Range<Key> = Range { start: Key::from("Rust".to_owned()), end: Key::from("TiKV".to_owned()) };
let from_explict_range: BoundRange = explict_range.into();
let range: Range<String> = "Rust".to_owned().."TiKV".to_owned();
let from_range: BoundRange = range.into();
assert_eq!(from_explict_range, from_range);
let range: RangeInclusive<String> = "Rust".to_owned()..="TiKV".to_owned();
let from_range: BoundRange = range.into();
assert_eq!(
from_range,
(Bound::Included(Key::from("Rust".to_owned())), Bound::Included(Key::from("TiKV".to_owned()))),
);
let range_from: RangeFrom<String> = "Rust".to_owned()..;
let from_range_from: BoundRange = range_from.into();
assert_eq!(
from_range_from,
(Bound::Included(Key::from("Rust".to_owned())), Bound::Unbounded),
);
Fields§
§from: Bound<Key>
§to: Bound<Key>
Implementations§
source§impl BoundRange
impl BoundRange
sourcepub fn new(from: Bound<Key>, to: Bound<Key>) -> BoundRange
pub fn new(from: Bound<Key>, to: Bound<Key>) -> BoundRange
Create a new BoundRange.
The caller must ensure that from
is not Unbounded
.
sourcepub fn range_from(from: Key) -> BoundRange
pub fn range_from(from: Key) -> BoundRange
Create a new BoundRange bounded below by from
and unbounded above.
sourcepub fn into_keys(self) -> (Key, Option<Key>)
pub fn into_keys(self) -> (Key, Option<Key>)
Ranges used in scanning TiKV have a particularity to them.
The start of a scan is inclusive, unless appended with an ‘\0’, then it is exclusive.
The end of a scan is exclusive, unless appended with an ‘\0’, then it is inclusive.
§Examples
use tikv_client::{BoundRange, Key, IntoOwnedRange};
// Exclusive
let range = "a".."z";
assert_eq!(
BoundRange::from(range.into_owned()).into_keys(),
(Key::from("a".to_owned()), Some(Key::from("z".to_owned()))),
);
// Inclusive
let range = "a"..="z";
assert_eq!(
BoundRange::from(range.into_owned()).into_keys(),
(Key::from("a".to_owned()), Some(Key::from("z\0".to_owned()))),
);
// Open right
let range = "a".to_owned()..;
assert_eq!(
BoundRange::from(range).into_keys(),
(Key::from("a".to_owned()), None),
);
// Left open right exclusive
let range = .."z";
assert_eq!(
BoundRange::from(range.into_owned()).into_keys(),
(Key::from("".to_owned()), Some(Key::from("z".to_owned()))),
);
// Left open right inclusive
let range = ..="z";
assert_eq!(
BoundRange::from(range.into_owned()).into_keys(),
(Key::from("".to_owned()), Some(Key::from("z\0".to_owned()))),
);
// Full range
let range = ..;
assert_eq!(
BoundRange::from(range).into_keys(),
(Key::from("".to_owned()), None),
);
Trait Implementations§
source§impl Clone for BoundRange
impl Clone for BoundRange
source§fn clone(&self) -> BoundRange
fn clone(&self) -> BoundRange
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for BoundRange
impl Debug for BoundRange
source§impl EncodeKeyspace for BoundRange
impl EncodeKeyspace for BoundRange
fn encode_keyspace(self, keyspace: Keyspace, key_mode: KeyMode) -> Self
source§impl<T: Into<Key>> From<(T, Option<T>)> for BoundRange
impl<T: Into<Key>> From<(T, Option<T>)> for BoundRange
source§fn from(other: (T, Option<T>)) -> BoundRange
fn from(other: (T, Option<T>)) -> BoundRange
source§impl<T: Into<Key>> From<(T, T)> for BoundRange
impl<T: Into<Key>> From<(T, T)> for BoundRange
source§fn from(other: (T, T)) -> BoundRange
fn from(other: (T, T)) -> BoundRange
source§impl<T: Into<Key>> From<Range<T>> for BoundRange
impl<T: Into<Key>> From<Range<T>> for BoundRange
source§fn from(other: Range<T>) -> BoundRange
fn from(other: Range<T>) -> BoundRange
source§impl<T: Into<Key>> From<RangeFrom<T>> for BoundRange
impl<T: Into<Key>> From<RangeFrom<T>> for BoundRange
source§fn from(other: RangeFrom<T>) -> BoundRange
fn from(other: RangeFrom<T>) -> BoundRange
source§impl From<RangeFull> for BoundRange
impl From<RangeFull> for BoundRange
source§fn from(_other: RangeFull) -> BoundRange
fn from(_other: RangeFull) -> BoundRange
source§impl<T: Into<Key>> From<RangeInclusive<T>> for BoundRange
impl<T: Into<Key>> From<RangeInclusive<T>> for BoundRange
source§fn from(other: RangeInclusive<T>) -> BoundRange
fn from(other: RangeInclusive<T>) -> BoundRange
source§impl<T: Into<Key>> From<RangeTo<T>> for BoundRange
impl<T: Into<Key>> From<RangeTo<T>> for BoundRange
source§fn from(other: RangeTo<T>) -> BoundRange
fn from(other: RangeTo<T>) -> BoundRange
source§impl<T: Into<Key>> From<RangeToInclusive<T>> for BoundRange
impl<T: Into<Key>> From<RangeToInclusive<T>> for BoundRange
source§fn from(other: RangeToInclusive<T>) -> BoundRange
fn from(other: RangeToInclusive<T>) -> BoundRange
source§impl<T: Into<Key> + Clone> PartialEq<(Bound<T>, Bound<T>)> for BoundRange
impl<T: Into<Key> + Clone> PartialEq<(Bound<T>, Bound<T>)> for BoundRange
source§impl PartialEq for BoundRange
impl PartialEq for BoundRange
source§fn eq(&self, other: &BoundRange) -> bool
fn eq(&self, other: &BoundRange) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl RangeBounds<Key> for BoundRange
impl RangeBounds<Key> for BoundRange
impl Eq for BoundRange
impl StructuralPartialEq for BoundRange
Auto Trait Implementations§
impl Freeze for BoundRange
impl RefUnwindSafe for BoundRange
impl Send for BoundRange
impl Sync for BoundRange
impl Unpin for BoundRange
impl UnwindSafe for BoundRange
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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