Skip to content

Commit 797960e

Browse files
authored
Improve rustfmt config (#401)
Signed-off-by: Andy Lok <andylokandy@hotmail.com>
1 parent 0a1de19 commit 797960e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+962
-596
lines changed

examples/common/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
use clap::{crate_version, App, Arg};
43
use std::path::PathBuf;
54

5+
use clap::crate_version;
6+
use clap::App;
7+
use clap::Arg;
8+
69
pub struct CommandArgs {
710
pub pd: Vec<String>,
811
pub ca: Option<PathBuf>,

examples/pessimistic.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
mod common;
44

5+
use tikv_client::Config;
6+
use tikv_client::Key;
7+
use tikv_client::TransactionClient as Client;
8+
use tikv_client::TransactionOptions;
9+
use tikv_client::Value;
10+
511
use crate::common::parse_args;
6-
use tikv_client::{Config, Key, TransactionClient as Client, TransactionOptions, Value};
712

813
#[tokio::main]
914
async fn main() {

examples/raw.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44

55
mod common;
66

7+
use tikv_client::Config;
8+
use tikv_client::IntoOwnedRange;
9+
use tikv_client::Key;
10+
use tikv_client::KvPair;
11+
use tikv_client::RawClient as Client;
12+
use tikv_client::Result;
13+
use tikv_client::Value;
14+
715
use crate::common::parse_args;
8-
use tikv_client::{Config, IntoOwnedRange, Key, KvPair, RawClient as Client, Result, Value};
916

1017
const KEY: &str = "TiKV";
1118
const VALUE: &str = "Rust";
@@ -93,10 +100,10 @@ async fn main() -> Result<()> {
93100
.expect("Could not scan");
94101

95102
let keys: Vec<_> = pairs.into_iter().map(|p| p.key().clone()).collect();
96-
assert_eq!(
97-
&keys,
98-
&[Key::from("k1".to_owned()), Key::from("k2".to_owned()),]
99-
);
103+
assert_eq!(&keys, &[
104+
Key::from("k1".to_owned()),
105+
Key::from("k2".to_owned()),
106+
]);
100107
println!("Scanning from {start:?} to {end:?} gives: {keys:?}");
101108

102109
let k1 = "k1";
@@ -115,18 +122,15 @@ async fn main() -> Result<()> {
115122
.into_iter()
116123
.map(|p| String::from_utf8(p.1).unwrap())
117124
.collect();
118-
assert_eq!(
119-
&vals,
120-
&[
121-
"v1".to_owned(),
122-
"v2".to_owned(),
123-
"v2".to_owned(),
124-
"v3".to_owned(),
125-
"v1".to_owned(),
126-
"v2".to_owned(),
127-
"v3".to_owned()
128-
]
129-
);
125+
assert_eq!(&vals, &[
126+
"v1".to_owned(),
127+
"v2".to_owned(),
128+
"v2".to_owned(),
129+
"v3".to_owned(),
130+
"v1".to_owned(),
131+
"v2".to_owned(),
132+
"v3".to_owned()
133+
]);
130134
println!("Scanning batch scan from {batch_scan_keys:?} gives: {vals:?}");
131135

132136
// Cleanly exit.

examples/transaction.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
mod common;
44

5+
use tikv_client::BoundRange;
6+
use tikv_client::Config;
7+
use tikv_client::Key;
8+
use tikv_client::KvPair;
9+
use tikv_client::TransactionClient as Client;
10+
use tikv_client::Value;
11+
512
use crate::common::parse_args;
6-
use tikv_client::{BoundRange, Config, Key, KvPair, TransactionClient as Client, Value};
713

814
async fn puts(client: &Client, pairs: impl IntoIterator<Item = impl Into<KvPair>>) {
915
let mut txn = client
@@ -104,10 +110,10 @@ async fn main() {
104110
let key1_exists = key_exists(&txn, key1.clone()).await;
105111
let key2: Key = b"key_not_exist".to_vec().into();
106112
let key2_exists = key_exists(&txn, key2.clone()).await;
107-
println!(
108-
"check exists {:?}",
109-
vec![(key1, key1_exists), (key2, key2_exists)]
110-
);
113+
println!("check exists {:?}", vec![
114+
(key1, key1_exists),
115+
(key2, key2_exists)
116+
]);
111117

112118
// scan
113119
let key1: Key = b"key1".to_vec().into();

rustfmt.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
imports_granularity="Crate"
1+
edition = "2021"
2+
version = "Two"
3+
reorder_imports = true
4+
imports_granularity = "Item"
5+
group_imports = "StdExternalCrate"
6+
where_single_line = true
7+
trailing_comma = "Vertical"
8+
overflow_delimited_expr = true
29
format_code_in_doc_comments = true
3-
edition = "2018"
10+
normalize_comments = true

src/backoff.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
// https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
44

5-
use rand::{thread_rng, Rng};
65
use std::time::Duration;
76

7+
use rand::thread_rng;
8+
use rand::Rng;
9+
810
pub const DEFAULT_REGION_BACKOFF: Backoff = Backoff::no_jitter_backoff(2, 500, 10);
911
pub const OPTIMISTIC_BACKOFF: Backoff = Backoff::no_jitter_backoff(2, 500, 10);
1012
pub const PESSIMISTIC_BACKOFF: Backoff = Backoff::no_jitter_backoff(2, 500, 10);
@@ -198,9 +200,10 @@ enum BackoffKind {
198200

199201
#[cfg(test)]
200202
mod test {
201-
use super::*;
202203
use std::convert::TryInto;
203204

205+
use super::*;
206+
204207
#[test]
205208
fn test_no_jitter_backoff() {
206209
// Tests for zero attempts.

src/compat.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
//! This module contains utility types and functions for making the transition
44
//! from futures 0.1 to 1.0 easier.
55
6-
use futures::{
7-
prelude::*,
8-
ready,
9-
task::{Context, Poll},
10-
};
116
use std::pin::Pin;
127

8+
use futures::prelude::*;
9+
use futures::ready;
10+
use futures::task::Context;
11+
use futures::task::Poll;
12+
1313
/// A future implementing a tail-recursive loop.
1414
///
1515
/// Created by the `loop_fn` function.

src/config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
use serde_derive::{Deserialize, Serialize};
4-
use std::{path::PathBuf, time::Duration};
3+
use std::path::PathBuf;
4+
use std::time::Duration;
5+
6+
use serde_derive::Deserialize;
7+
use serde_derive::Serialize;
58

69
/// The configuration for either a [`RawClient`](crate::RawClient) or a
710
/// [`TransactionClient`](crate::TransactionClient).

src/kv/bound_range.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
use std::{
4-
borrow::Borrow,
5-
cmp::{Eq, PartialEq},
6-
ops::{
7-
Bound, Range, RangeBounds, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive,
8-
},
9-
};
3+
use std::borrow::Borrow;
4+
use std::cmp::Eq;
5+
use std::cmp::PartialEq;
6+
use std::ops::Bound;
7+
use std::ops::Range;
8+
use std::ops::RangeBounds;
9+
use std::ops::RangeFrom;
10+
use std::ops::RangeFull;
11+
use std::ops::RangeInclusive;
12+
use std::ops::RangeTo;
13+
use std::ops::RangeToInclusive;
1014

1115
#[cfg(test)]
1216
use proptest_derive::Arbitrary;

src/kv/codec.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use std::{io::Write, ptr};
1+
use std::io::Write;
2+
use std::ptr;
3+
24
use tikv_client_common::internal_err;
35

46
use crate::Result;
@@ -153,26 +155,18 @@ pub mod test {
153155
#[test]
154156
fn test_enc_dec_bytes() {
155157
let pairs = vec![
156-
(
157-
vec![],
158-
vec![0, 0, 0, 0, 0, 0, 0, 0, 247],
159-
vec![255, 255, 255, 255, 255, 255, 255, 255, 8],
160-
),
161-
(
162-
vec![0],
163-
vec![0, 0, 0, 0, 0, 0, 0, 0, 248],
164-
vec![255, 255, 255, 255, 255, 255, 255, 255, 7],
165-
),
166-
(
167-
vec![1, 2, 3],
168-
vec![1, 2, 3, 0, 0, 0, 0, 0, 250],
169-
vec![254, 253, 252, 255, 255, 255, 255, 255, 5],
170-
),
171-
(
172-
vec![1, 2, 3, 0],
173-
vec![1, 2, 3, 0, 0, 0, 0, 0, 251],
174-
vec![254, 253, 252, 255, 255, 255, 255, 255, 4],
175-
),
158+
(vec![], vec![0, 0, 0, 0, 0, 0, 0, 0, 247], vec![
159+
255, 255, 255, 255, 255, 255, 255, 255, 8,
160+
]),
161+
(vec![0], vec![0, 0, 0, 0, 0, 0, 0, 0, 248], vec![
162+
255, 255, 255, 255, 255, 255, 255, 255, 7,
163+
]),
164+
(vec![1, 2, 3], vec![1, 2, 3, 0, 0, 0, 0, 0, 250], vec![
165+
254, 253, 252, 255, 255, 255, 255, 255, 5,
166+
]),
167+
(vec![1, 2, 3, 0], vec![1, 2, 3, 0, 0, 0, 0, 0, 251], vec![
168+
254, 253, 252, 255, 255, 255, 255, 255, 4,
169+
]),
176170
(
177171
vec![1, 2, 3, 4, 5, 6, 7],
178172
vec![1, 2, 3, 4, 5, 6, 7, 0, 254],

0 commit comments

Comments
 (0)