Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ license = "Apache-2.0"
authors = ["The TiKV Project Authors"]
repository = "https://github.com/tikv/client-rust"
description = "The rust language implementation of TiKV client."
edition = "2018"

[lib]
name = "tikv_client"
Expand Down
6 changes: 1 addition & 5 deletions examples/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

extern crate futures;
extern crate tikv_client;

use std::path::PathBuf;

use futures::future::Future;
use std::path::PathBuf;
use tikv_client::*;

fn main() {
Expand Down
24 changes: 13 additions & 11 deletions examples/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

extern crate futures;
extern crate tikv_client;

use futures::{future, Future, Stream};
use std::ops::RangeBounds;
use std::path::PathBuf;

use futures::{future, Future, Stream};
use tikv_client::transaction::{Client, IsolationLevel};
use tikv_client::*;
use tikv_client::{
transaction::{Client, IsolationLevel},
Config, Key, KvPair, Value,
Comment thread
Hoverbear marked this conversation as resolved.
};

fn puts(client: &Client, pairs: impl IntoIterator<Item = impl Into<KvPair>>) {
let mut txn = client.begin();
Expand All @@ -28,7 +26,8 @@ fn puts(client: &Client, pairs: impl IntoIterator<Item = impl Into<KvPair>>) {
.into_iter()
.map(Into::into)
.map(|p| txn.set(p.key().clone(), p.value().clone())),
).wait()
)
.wait()
.expect("Could not set key value pairs");
txn.commit().wait().expect("Could not commit transaction");
}
Expand All @@ -49,10 +48,12 @@ fn scan(client: &Client, range: impl RangeBounds<Key>, mut limit: usize) {
limit -= 1;
true
})
}).for_each(|pair| {
})
.for_each(|pair| {
println!("{:?}", pair);
Ok(())
}).wait()
})
.wait()
.expect("Could not scan keys");
}

Expand All @@ -63,7 +64,8 @@ fn dels(client: &Client, keys: impl IntoIterator<Item = Key>) {
.into_iter()
.map(|p| {
txn.delete(p).wait().expect("Could not delete key");
}).collect();
})
.collect();
txn.commit().wait().expect("Could not commit transaction");
}

Expand Down
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stable
9 changes: 5 additions & 4 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::error;
use std::result;
use grpcio;
use quick_error::quick_error;
use std::{error, result};

quick_error!{
quick_error! {
#[derive(Debug)]
pub enum Error {
Io(err: ::std::io::Error) {
from()
cause(err)
description(err.description())
}
Grpc(err: ::grpc::Error) {
Grpc(err: grpcio::Error) {
from()
cause(err)
description(err.description())
Expand Down
17 changes: 5 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

extern crate futures;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate quick_error;
extern crate grpcio as grpc;
use serde_derive::*;
use std::ops::Deref;
use std::path::PathBuf;

pub mod errors;
pub mod raw;
pub mod transaction;

use std::ops::Deref;
use std::path::PathBuf;

pub use errors::Error;
pub use errors::Result;
pub use crate::errors::Error;
pub use crate::errors::Result;

#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct Key(Vec<u8>);
Expand Down
8 changes: 3 additions & 5 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::ops::RangeBounds;

use crate::{Config, Error, Key, KvPair, Value};
use futures::{Future, Poll};

use {Config, Error, Key, KvPair, Value};
use std::ops::RangeBounds;

#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct ColumnFamily(String);
Expand Down Expand Up @@ -388,7 +386,7 @@ impl Future for Connect {
pub struct Client;

impl Client {
#![cfg_attr(feature = "cargo-clippy", allow(new_ret_no_self))]
#![allow(clippy::new_ret_no_self)]
pub fn new(config: &Config) -> Connect {
Connect::new(config.clone())
}
Expand Down
8 changes: 3 additions & 5 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::ops::RangeBounds;

use crate::{Config, Error, Key, KvPair, Value};
use futures::{Future, Poll, Stream};

use {Config, Error, Key, KvPair, Value};
use std::ops::RangeBounds;

#[derive(Copy, Clone)]
pub struct Timestamp(u64);
Expand Down Expand Up @@ -302,7 +300,7 @@ impl Future for Connect {
pub struct Client {}

impl Client {
#![cfg_attr(feature = "cargo-clippy", allow(new_ret_no_self))]
#![allow(clippy::new_ret_no_self)]
pub fn new(config: &Config) -> Connect {
Connect::new(config.clone())
}
Expand Down