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

source

pub fn new(from: Bound<Key>, to: Bound<Key>) -> BoundRange

Create a new BoundRange.

The caller must ensure that from is not Unbounded.

source

pub fn range_from(from: Key) -> BoundRange

Create a new BoundRange bounded below by from and unbounded above.

source

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

source§

fn clone(&self) -> BoundRange

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 BoundRange

source§

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

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

impl EncodeKeyspace for BoundRange

source§

fn encode_keyspace(self, keyspace: Keyspace, key_mode: KeyMode) -> Self

source§

impl<T: Into<Key> + Eq> From<(Bound<T>, Bound<T>)> for BoundRange

source§

fn from(bounds: (Bound<T>, Bound<T>)) -> BoundRange

Converts to this type from the input type.
source§

impl<T: Into<Key>> From<(T, Option<T>)> for BoundRange

source§

fn from(other: (T, Option<T>)) -> BoundRange

Converts to this type from the input type.
source§

impl<T: Into<Key>> From<(T, T)> for BoundRange

source§

fn from(other: (T, T)) -> BoundRange

Converts to this type from the input type.
source§

impl<T: Into<Key>> From<Range<T>> for BoundRange

source§

fn from(other: Range<T>) -> BoundRange

Converts to this type from the input type.
source§

impl<T: Into<Key>> From<RangeFrom<T>> for BoundRange

source§

fn from(other: RangeFrom<T>) -> BoundRange

Converts to this type from the input type.
source§

impl From<RangeFull> for BoundRange

source§

fn from(_other: RangeFull) -> BoundRange

Converts to this type from the input type.
source§

impl<T: Into<Key>> From<RangeInclusive<T>> for BoundRange

source§

fn from(other: RangeInclusive<T>) -> BoundRange

Converts to this type from the input type.
source§

impl<T: Into<Key>> From<RangeTo<T>> for BoundRange

source§

fn from(other: RangeTo<T>) -> BoundRange

Converts to this type from the input type.
source§

impl<T: Into<Key>> From<RangeToInclusive<T>> for BoundRange

source§

fn from(other: RangeToInclusive<T>) -> BoundRange

Converts to this type from the input type.
source§

impl<T: Into<Key> + Clone> PartialEq<(Bound<T>, Bound<T>)> for BoundRange

source§

fn eq(&self, other: &(Bound<T>, Bound<T>)) -> 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 PartialEq for BoundRange

source§

fn eq(&self, other: &BoundRange) -> 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 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) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

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

impl Eq for BoundRange

source§

impl StructuralPartialEq for BoundRange

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

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

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

source§

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

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

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn from_ref(input: &T) -> T

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

impl<T> Instrument for T

source§

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

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

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 T
where 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
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 T
where 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 T
where 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 T
where 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.
source§

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

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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