diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef91217..82d62fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,8 @@ jobs: profile: minimal toolchain: nightly override: true + - name: Rust Cache + uses: Swatinem/rust-cache@v1.4.0 - uses: actions-rs/cargo@v1 with: command: check @@ -47,6 +49,8 @@ jobs: toolchain: nightly components: clippy override: true + - name: Rust Cache + uses: Swatinem/rust-cache@v1.4.0 - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -64,18 +68,8 @@ jobs: profile: minimal toolchain: nightly override: true - - run: cargo generate-lockfile - - name: Cache dependencies - uses: actions/cache@v2 - env: - cache-name: cache-dependencies - with: - path: | - ~/.cargo/.crates.toml - ~/.cargo/.crates2.json - ~/.cargo/registry/index - ~/.cargo/registry/cache - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }} + - name: Rust Cache + uses: Swatinem/rust-cache@v1.4.0 - name: unit test run: make unit-test integration-test: @@ -90,18 +84,8 @@ jobs: profile: minimal toolchain: nightly override: true - - run: cargo generate-lockfile - - name: Cache dependencies - uses: actions/cache@v2 - env: - cache-name: cache-dependencies - with: - path: | - ~/.cargo/.crates.toml - ~/.cargo/.crates2.json - ~/.cargo/registry/index - ~/.cargo/registry/cache - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }} + - name: Rust Cache + uses: Swatinem/rust-cache@v1.4.0 - name: install tiup run: curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh - name: start tiup playground diff --git a/examples/raw.rs b/examples/raw.rs index aefd731..de583d8 100644 --- a/examples/raw.rs +++ b/examples/raw.rs @@ -27,6 +27,7 @@ async fn main() -> Result<()> { // When we first create a client we receive a `Connect` structure which must be resolved before // the client is actually connected and usable. let client = Client::new_with_config(args.pd, config, None).await?; + let client = client.clone(); // Requests are created from the connected client. These calls return structures which // implement `Future`. This means the `Future` must be resolved before the action ever takes diff --git a/src/config.rs b/src/config.rs index 8f5e28e..a0ee3ab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,7 +8,7 @@ use std::{path::PathBuf, time::Duration}; /// /// See also [`TransactionOptions`](crate::TransactionOptions) which provides more ways to configure /// requests. -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(default)] #[serde(rename_all = "kebab-case")] pub struct Config { diff --git a/src/raw/client.rs b/src/raw/client.rs index 3252e40..6f140ad 100644 --- a/src/raw/client.rs +++ b/src/raw/client.rs @@ -25,7 +25,6 @@ const MAX_RAW_KV_SCAN_LIMIT: u32 = 10240; /// /// The returned results of raw request methods are [`Future`](std::future::Future)s that must be /// awaited to execute. -#[derive(Clone)] pub struct Client { rpc: Arc, cf: Option, @@ -34,6 +33,17 @@ pub struct Client { logger: Logger, } +impl Clone for Client { + fn clone(&self) -> Self { + Self { + rpc: self.rpc.clone(), + cf: self.cf.clone(), + atomic: self.atomic, + logger: self.logger.clone(), + } + } +} + impl Client { /// Create a raw [`Client`] and connect to the TiKV cluster. /// diff --git a/src/transaction/client.rs b/src/transaction/client.rs index fee8e25..69f11bc 100644 --- a/src/transaction/client.rs +++ b/src/transaction/client.rs @@ -38,6 +38,15 @@ pub struct Client { logger: Logger, } +impl Clone for Client { + fn clone(&self) -> Self { + Self { + pd: self.pd.clone(), + logger: self.logger.clone(), + } + } +} + impl Client { /// Create a transactional [`Client`] and connect to the TiKV cluster. /// diff --git a/src/transaction/transaction.rs b/src/transaction/transaction.rs index f067f66..0f4197d 100644 --- a/src/transaction/transaction.rs +++ b/src/transaction/transaction.rs @@ -953,7 +953,7 @@ pub struct TransactionOptions { heartbeat_option: HeartbeatOption, } -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, PartialEq, Eq, Debug)] pub enum HeartbeatOption { NoHeartbeat, FixedTime(Duration), @@ -1308,7 +1308,7 @@ impl Committer { } } -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] enum TransactionStatus { /// The transaction is read-only [`Snapshot`](super::Snapshot), no need to commit or rollback or panic on drop. ReadOnly,