Skip to content

Commit

Permalink
Chore: remove excess dependencies (#4)
Browse files Browse the repository at this point in the history
* Deps: use `futures_core` over `futures` to minimize dependencies

This practically cuts the number of dependencies by half.

* Deps: use `futures-util` in test dependencies

* Chore: remove redundant use of `^` semver range

Cargo uses the `^` semver range by default.

* Chore: remove dependency on `tokio-test` macros
  • Loading branch information
BastiDood committed Aug 24, 2021
1 parent 1779e85 commit c413778
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 90 deletions.
12 changes: 4 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@ maintenance = { status = "actively-developed" }

[dependencies]
tokio = { version = "1", features = ["sync", "time"] }
futures = "0.3"
futures-core = { version = "0.3", default-features = false }

[dev-dependencies]
futures-util = { version = "0.3", default-features = false }
tokio = { version = "1", features = ["test-util", "rt", "rt-multi-thread", "macros"] }
tokio-test = "^0.4"
loom = { version = "^0.4.0" }
criterion = { version="^0.3.4", features = ["async_tokio", "html_reports"] }

[target.'cfg(loom)'.dependencies]
loom = { version = "^0.4.0", features = ["futures", "checkpoint"] }
loom = { version = "0.5", features = ["futures", "checkpoint"] }
criterion = { version = "0.3", features = ["async_tokio", "html_reports"] }

[[test]]
name = "tests"
Expand All @@ -45,7 +42,6 @@ name = "tests"
name = "bench_channel_async"
harness = false


[[bench]]
name = "bench_channel_sync"
harness = false
2 changes: 1 addition & 1 deletion src/bounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::error::{ReceiveError, RequestError, RespondError, SendError};
use tokio::sync::{mpsc, oneshot};
use tokio::time::{timeout, Duration};

use futures::Stream;
use futures_core::Stream;
use std::pin::Pin;
use std::task::{Context, Poll};

Expand Down
21 changes: 9 additions & 12 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::error::Error;
use std::fmt;
use tokio::sync::mpsc::error::{RecvError as MpscRecvError, SendError as MpscSendError};
use tokio::sync::mpsc::error::SendError as MpscSendError;
use tokio::sync::oneshot;

/// Error thrown when a [`RequestSender::send()`](crate::RequestSender::send()) or [`UnboundedRequestSender::send()`](crate::unbounded::UnboundedRequestSender::send())
Expand Down Expand Up @@ -51,13 +51,6 @@ pub enum ReceiveError {
TimeoutError,
}

// Cannot test this due to private field in the tokio error implementation
#[cfg(not(tarpaulin_include))]
impl<T> From<MpscRecvError> for RequestError<T> {
fn from(_err: MpscRecvError) -> RequestError<T> {
RequestError::RecvError
}
}
impl<T> From<SendError<T>> for RequestError<T> {
fn from(err: SendError<T>) -> RequestError<T> {
RequestError::SendError(err.0)
Expand Down Expand Up @@ -104,10 +97,14 @@ impl<T> Error for RequestError<T> where T: fmt::Debug {}

impl fmt::Display for ReceiveError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "{}", match self {
ReceiveError::RecvError => "receive channel closed",
ReceiveError::TimeoutError => "request timed out"
})
write!(
fmt,
"{}",
match self {
ReceiveError::RecvError => "receive channel closed",
ReceiveError::TimeoutError => "request timed out",
}
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/unbounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::bounded::ResponseReceiver;
use tokio::sync::{mpsc, oneshot};
use tokio::time::Duration;

use futures::Stream;
use futures_core::Stream;
use std::pin::Pin;
use std::task::{Context, Poll};

Expand Down
15 changes: 6 additions & 9 deletions tests/loom_bounded.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use loom::future::block_on;
use loom::thread;
use tokio_test::assert_err;
use tokio_test::assert_ok;

#[test]
#[cfg(not(tarpaulin))]
Expand All @@ -11,15 +9,15 @@ fn closing_tx() {

thread::spawn(move || {
let res = block_on(tx.send(4));
assert_ok!(res);
assert!(res.is_ok());
drop(tx);
});

let v = block_on(rx.recv());
assert_ok!(v);
assert!(v.is_ok());

let v = block_on(rx.recv());
assert_err!(v);
assert!(v.is_err());
})
}

Expand All @@ -32,17 +30,16 @@ fn closing_tx_res() {
thread::spawn(move || {
let res = block_on(tx.send(5));
let repl = block_on(res.unwrap().recv());
assert_ok!(repl);
assert_eq!(repl.unwrap(), 10);
assert_eq!(repl, Ok(10));
drop(tx);
});

let v = block_on(rx.recv());
let (req, responder) = v.unwrap();
let v = responder.respond(req * 2);
assert_ok!(v);
assert!(v.is_ok());

let v = block_on(rx.recv());
assert_err!(v);
assert!(v.is_err());
})
}

0 comments on commit c413778

Please sign in to comment.