Struct tikv_client::BoundRange[][src]

pub struct BoundRange {
    from: Bound<Key>,
    to: Bound<Key>,
}

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

impl BoundRange[src]

fn new(from: Bound<Key>, to: Bound<Key>) -> BoundRange[src]

Create a new BoundRange.

The caller must ensure that from is not Unbounded.

pub fn range_from(from: Key) -> BoundRange[src]

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

pub fn into_keys(self) -> (Key, Option<Key>)[src]

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

impl Clone for BoundRange[src]

impl Debug for BoundRange[src]

impl Eq for BoundRange[src]

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

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

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

impl From<KeyRange> for BoundRange[src]

impl<T: Into<Key>> From<Range<T>> for BoundRange[src]

impl<T: Into<Key>> From<RangeFrom<T>> for BoundRange[src]

impl From<RangeFull> for BoundRange[src]

impl<T: Into<Key>> From<RangeInclusive<T>> for BoundRange[src]

impl<T: Into<Key>> From<RangeTo<T>> for BoundRange[src]

impl<T: Into<Key>> From<RangeToInclusive<T>> for BoundRange[src]

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

impl PartialEq<BoundRange> for BoundRange[src]

impl RangeBounds<Key> for BoundRange[src]

impl StructuralEq for BoundRange[src]

impl StructuralPartialEq for BoundRange[src]

Auto Trait Implementations

impl RefUnwindSafe for BoundRange

impl Send for BoundRange

impl Sync for BoundRange

impl Unpin for BoundRange

impl UnwindSafe for BoundRange

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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>, 
[src]