mirror of https://github.com/tikv/client-rust.git
refactor: fix nightly cargo clippy
Signed-off-by: ekexium <ekexium@gmail.com>
This commit is contained in:
parent
3392e6341b
commit
578be6cff2
|
@ -5,7 +5,7 @@
|
|||
mod common;
|
||||
|
||||
use crate::common::parse_args;
|
||||
use tikv_client::{Config, Key, KvPair, RawClient as Client, Result, ToOwnedRange, Value};
|
||||
use tikv_client::{Config, IntoOwnedRange, Key, KvPair, RawClient as Client, Result, Value};
|
||||
|
||||
const KEY: &str = "TiKV";
|
||||
const VALUE: &str = "Rust";
|
||||
|
@ -86,7 +86,7 @@ async fn main() -> Result<()> {
|
|||
let start = "k1";
|
||||
let end = "k2";
|
||||
let pairs = client
|
||||
.scan((start..=end).to_owned(), 10)
|
||||
.scan((start..=end).into_owned(), 10)
|
||||
.await
|
||||
.expect("Could not scan");
|
||||
|
||||
|
|
|
@ -83,41 +83,41 @@ impl BoundRange {
|
|||
///
|
||||
/// # Examples
|
||||
/// ```rust
|
||||
/// use tikv_client::{BoundRange, Key, ToOwnedRange};
|
||||
/// use tikv_client::{BoundRange, Key, IntoOwnedRange};
|
||||
/// // Exclusive
|
||||
/// let range = "a".."z";
|
||||
/// assert_eq!(
|
||||
/// BoundRange::from(range.to_owned()).into_keys(),
|
||||
/// 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.to_owned()).into_keys(),
|
||||
/// 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.to_owned()).into_keys(),
|
||||
/// BoundRange::from(range).into_keys(),
|
||||
/// (Key::from("a".to_owned()), None),
|
||||
/// );
|
||||
/// // Left open right exclusive
|
||||
/// let range = .."z";
|
||||
/// assert_eq!(
|
||||
/// BoundRange::from(range.to_owned()).into_keys(),
|
||||
/// 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.to_owned()).into_keys(),
|
||||
/// 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.to_owned()).into_keys(),
|
||||
/// BoundRange::from(range).into_keys(),
|
||||
/// (Key::from("".to_owned()), None),
|
||||
/// );
|
||||
// ```
|
||||
|
@ -249,9 +249,9 @@ impl<T: Into<Key> + Eq> From<(Bound<T>, Bound<T>)> for BoundRange {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<kvrpcpb::KeyRange> for BoundRange {
|
||||
fn into(self) -> kvrpcpb::KeyRange {
|
||||
let (start, end) = self.into_keys();
|
||||
impl From<BoundRange> for kvrpcpb::KeyRange {
|
||||
fn from(bound_range: BoundRange) -> Self {
|
||||
let (start, end) = bound_range.into_keys();
|
||||
let mut range = kvrpcpb::KeyRange::default();
|
||||
range.set_start_key(start.into());
|
||||
range.set_end_key(end.unwrap_or_default().into());
|
||||
|
@ -271,36 +271,36 @@ impl From<kvrpcpb::KeyRange> for BoundRange {
|
|||
///
|
||||
/// # Examples
|
||||
/// ```rust
|
||||
/// # use tikv_client::{ToOwnedRange, BoundRange};
|
||||
/// # use tikv_client::{IntoOwnedRange, BoundRange};
|
||||
/// # use std::ops::*;
|
||||
/// let r1: Range<&str> = "s".."e";
|
||||
/// let r1: BoundRange = r1.to_owned();
|
||||
/// let r1: BoundRange = r1.into_owned();
|
||||
///
|
||||
/// let r2: RangeFrom<&str> = "start"..;
|
||||
/// let r2: BoundRange = r2.to_owned();
|
||||
/// let r2: BoundRange = r2.into_owned();
|
||||
///
|
||||
/// let r3: RangeInclusive<&str> = "s"..="e";
|
||||
/// let r3: BoundRange = r3.to_owned();
|
||||
/// let r3: BoundRange = r3.into_owned();
|
||||
///
|
||||
/// let r4: RangeTo<&str> = .."z";
|
||||
/// let r4: BoundRange = r4.to_owned();
|
||||
/// let r4: BoundRange = r4.into_owned();
|
||||
///
|
||||
/// let k1: Vec<u8> = "start".to_owned().into_bytes();
|
||||
/// let k2: Vec<u8> = "end".to_owned().into_bytes();
|
||||
/// let r4: BoundRange = (&k1, &k2).to_owned();
|
||||
/// let r5: BoundRange = (&k1, None).to_owned();
|
||||
/// let r6: BoundRange = (&k1, Some(&k2)).to_owned();
|
||||
/// let r4: BoundRange = (&k1, &k2).into_owned();
|
||||
/// let r5: BoundRange = (&k1, None).into_owned();
|
||||
/// let r6: BoundRange = (&k1, Some(&k2)).into_owned();
|
||||
/// ```
|
||||
pub trait ToOwnedRange {
|
||||
pub trait IntoOwnedRange {
|
||||
/// Transform a borrowed range of some form into an owned `BoundRange`.
|
||||
fn to_owned(self) -> BoundRange;
|
||||
fn into_owned(self) -> BoundRange;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_owned() {}
|
||||
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> ToOwnedRange for Range<&U> {
|
||||
fn to_owned(self) -> BoundRange {
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> IntoOwnedRange for Range<&U> {
|
||||
fn into_owned(self) -> BoundRange {
|
||||
From::from(Range {
|
||||
start: self.start.to_owned(),
|
||||
end: self.end.to_owned(),
|
||||
|
@ -308,53 +308,55 @@ impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> ToOwnedRange for
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> ToOwnedRange for RangeFrom<&U> {
|
||||
fn to_owned(self) -> BoundRange {
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> IntoOwnedRange for RangeFrom<&U> {
|
||||
fn into_owned(self) -> BoundRange {
|
||||
From::from(RangeFrom {
|
||||
start: self.start.to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> ToOwnedRange for RangeTo<&U> {
|
||||
fn to_owned(self) -> BoundRange {
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> IntoOwnedRange for RangeTo<&U> {
|
||||
fn into_owned(self) -> BoundRange {
|
||||
From::from(RangeTo {
|
||||
end: self.end.to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> ToOwnedRange for RangeInclusive<&U> {
|
||||
fn to_owned(self) -> BoundRange {
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> IntoOwnedRange
|
||||
for RangeInclusive<&U>
|
||||
{
|
||||
fn into_owned(self) -> BoundRange {
|
||||
let (from, to) = self.into_inner();
|
||||
From::from(RangeInclusive::new(from.to_owned(), to.to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> ToOwnedRange
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> IntoOwnedRange
|
||||
for RangeToInclusive<&U>
|
||||
{
|
||||
fn to_owned(self) -> BoundRange {
|
||||
fn into_owned(self) -> BoundRange {
|
||||
From::from(RangeToInclusive {
|
||||
end: self.end.to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToOwnedRange for RangeFull {
|
||||
fn to_owned(self) -> BoundRange {
|
||||
impl IntoOwnedRange for RangeFull {
|
||||
fn into_owned(self) -> BoundRange {
|
||||
From::from(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> ToOwnedRange for (&U, Option<&U>) {
|
||||
fn to_owned(self) -> BoundRange {
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> IntoOwnedRange for (&U, Option<&U>) {
|
||||
fn into_owned(self) -> BoundRange {
|
||||
From::from((self.0.to_owned(), self.1.map(|u| u.to_owned())))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> ToOwnedRange for (&U, &U) {
|
||||
fn to_owned(self) -> BoundRange {
|
||||
impl<T: Into<Key> + Borrow<U>, U: ToOwned<Owned = T> + ?Sized> IntoOwnedRange for (&U, &U) {
|
||||
fn into_owned(self) -> BoundRange {
|
||||
From::from((self.0.to_owned(), self.1.to_owned()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,15 +140,15 @@ impl From<String> for Key {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Vec<u8>> for Key {
|
||||
fn into(self) -> Vec<u8> {
|
||||
self.0
|
||||
impl From<Key> for Vec<u8> {
|
||||
fn from(key: Key) -> Self {
|
||||
key.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Into<&'a [u8]> for &'a Key {
|
||||
fn into(self) -> &'a [u8] {
|
||||
&self.0
|
||||
impl<'a> From<&'a Key> for &'a [u8] {
|
||||
fn from(key: &'a Key) -> Self {
|
||||
&key.0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,9 +90,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<(Key, Value)> for KvPair {
|
||||
fn into(self) -> (Key, Value) {
|
||||
(self.0, self.1)
|
||||
impl From<KvPair> for (Key, Value) {
|
||||
fn from(pair: KvPair) -> Self {
|
||||
(pair.0, pair.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,10 +102,10 @@ impl From<kvrpcpb::KvPair> for KvPair {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<kvrpcpb::KvPair> for KvPair {
|
||||
fn into(self) -> kvrpcpb::KvPair {
|
||||
impl From<KvPair> for kvrpcpb::KvPair {
|
||||
fn from(pair: KvPair) -> Self {
|
||||
let mut result = kvrpcpb::KvPair::default();
|
||||
let (key, value) = self.into();
|
||||
let (key, value) = pair.into();
|
||||
result.set_key(key.into());
|
||||
result.set_value(value);
|
||||
result
|
||||
|
|
|
@ -7,7 +7,7 @@ mod key;
|
|||
mod kvpair;
|
||||
mod value;
|
||||
|
||||
pub use bound_range::{BoundRange, ToOwnedRange};
|
||||
pub use bound_range::{BoundRange, IntoOwnedRange};
|
||||
pub use key::Key;
|
||||
pub use kvpair::KvPair;
|
||||
pub use value::Value;
|
||||
|
|
|
@ -101,7 +101,7 @@ extern crate log;
|
|||
#[doc(inline)]
|
||||
pub use crate::backoff::Backoff;
|
||||
#[doc(inline)]
|
||||
pub use crate::kv::{BoundRange, Key, KvPair, ToOwnedRange, Value};
|
||||
pub use crate::kv::{BoundRange, IntoOwnedRange, Key, KvPair, Value};
|
||||
#[doc(inline)]
|
||||
pub use crate::raw::{Client as RawClient, ColumnFamily};
|
||||
#[doc(inline)]
|
||||
|
|
|
@ -170,7 +170,7 @@ impl Client {
|
|||
///
|
||||
/// # Examples
|
||||
/// ```rust,no_run
|
||||
/// # use tikv_client::{Result, KvPair, Key, Value, Config, RawClient, ToOwnedRange};
|
||||
/// # use tikv_client::{Result, KvPair, Key, Value, Config, RawClient, IntoOwnedRange};
|
||||
/// # use futures::prelude::*;
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap();
|
||||
|
@ -242,12 +242,12 @@ impl Client {
|
|||
///
|
||||
/// # Examples
|
||||
/// ```rust,no_run
|
||||
/// # use tikv_client::{Key, Config, RawClient, ToOwnedRange};
|
||||
/// # use tikv_client::{Key, Config, RawClient, IntoOwnedRange};
|
||||
/// # use futures::prelude::*;
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap();
|
||||
/// let inclusive_range = "TiKV"..="TiDB";
|
||||
/// let req = client.delete_range(inclusive_range.to_owned());
|
||||
/// let req = client.delete_range(inclusive_range.into_owned());
|
||||
/// let result: () = req.await.unwrap();
|
||||
/// # });
|
||||
/// ```
|
||||
|
@ -267,12 +267,12 @@ impl Client {
|
|||
///
|
||||
/// # Examples
|
||||
/// ```rust,no_run
|
||||
/// # use tikv_client::{KvPair, Config, RawClient, ToOwnedRange};
|
||||
/// # use tikv_client::{KvPair, Config, RawClient, IntoOwnedRange};
|
||||
/// # use futures::prelude::*;
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap();
|
||||
/// let inclusive_range = "TiKV"..="TiDB";
|
||||
/// let req = client.scan(inclusive_range.to_owned(), 2);
|
||||
/// let req = client.scan(inclusive_range.into_owned(), 2);
|
||||
/// let result: Vec<KvPair> = req.await.unwrap();
|
||||
/// # });
|
||||
/// ```
|
||||
|
@ -290,12 +290,12 @@ impl Client {
|
|||
///
|
||||
/// # Examples
|
||||
/// ```rust,no_run
|
||||
/// # use tikv_client::{Key, Config, RawClient, ToOwnedRange};
|
||||
/// # use tikv_client::{Key, Config, RawClient, IntoOwnedRange};
|
||||
/// # use futures::prelude::*;
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap();
|
||||
/// let inclusive_range = "TiKV"..="TiDB";
|
||||
/// let req = client.scan_keys(inclusive_range.to_owned(), 2);
|
||||
/// let req = client.scan_keys(inclusive_range.into_owned(), 2);
|
||||
/// let result: Vec<Key> = req.await.unwrap();
|
||||
/// # });
|
||||
/// ```
|
||||
|
@ -320,13 +320,13 @@ impl Client {
|
|||
///
|
||||
/// # Examples
|
||||
/// ```rust,no_run
|
||||
/// # use tikv_client::{Key, Config, RawClient, ToOwnedRange};
|
||||
/// # use tikv_client::{Key, Config, RawClient, IntoOwnedRange};
|
||||
/// # use futures::prelude::*;
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap();
|
||||
/// let inclusive_range1 = "TiDB"..="TiKV";
|
||||
/// let inclusive_range2 = "TiKV"..="TiSpark";
|
||||
/// let iterable = vec![inclusive_range1.to_owned(), inclusive_range2.to_owned()];
|
||||
/// let iterable = vec![inclusive_range1.into_owned(), inclusive_range2.into_owned()];
|
||||
/// let req = client.batch_scan(iterable, 2);
|
||||
/// let result = req.await;
|
||||
/// # });
|
||||
|
@ -351,13 +351,13 @@ impl Client {
|
|||
///
|
||||
/// # Examples
|
||||
/// ```rust,no_run
|
||||
/// # use tikv_client::{Key, Config, RawClient, ToOwnedRange};
|
||||
/// # use tikv_client::{Key, Config, RawClient, IntoOwnedRange};
|
||||
/// # use futures::prelude::*;
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap();
|
||||
/// let inclusive_range1 = "TiDB"..="TiKV";
|
||||
/// let inclusive_range2 = "TiKV"..="TiSpark";
|
||||
/// let iterable = vec![inclusive_range1.to_owned(), inclusive_range2.to_owned()];
|
||||
/// let iterable = vec![inclusive_range1.into_owned(), inclusive_range2.into_owned()];
|
||||
/// let req = client.batch_scan(iterable, 2);
|
||||
/// let result = req.await;
|
||||
/// # });
|
||||
|
|
Loading…
Reference in New Issue