Skip to content

Commit

Permalink
Add blanket impl of AtatClient for mutable reference (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKoch authored Jul 16, 2024
1 parent a086f0d commit a466836
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
9 changes: 9 additions & 0 deletions atat/src/asynch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ pub trait AtatClient {
Err(Error::Timeout)
}
}

impl<T> AtatClient for &mut T
where
T: AtatClient,
{
async fn send<Cmd: AtatCmd>(&mut self, cmd: &Cmd) -> Result<Cmd::Response, Error> {

Check warning on line 43 in atat/src/asynch/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

future cannot be sent between threads safely

warning: future cannot be sent between threads safely --> atat/src/asynch/mod.rs:43:5 | 43 | async fn send<Cmd: AtatCmd>(&mut self, cmd: &Cmd) -> Result<Cmd::Response, Error> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `send` is not `Send` | note: future is not `Send` as it awaits another future which is not `Send` --> atat/src/asynch/mod.rs:44:9 | 44 | T::send(self, cmd).await | ^^^^^^^^^^^^^^^^^^ await occurs here on type `impl futures::Future<Output = core::result::Result<<Cmd as traits::AtatCmd>::Response, error::Error>>`, which is not `Send` = note: `impl futures::Future<Output = core::result::Result<<Cmd as traits::AtatCmd>::Response, error::Error>>` doesn't implement `core::marker::Send` note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` --> atat/src/asynch/mod.rs:43:44 | 43 | async fn send<Cmd: AtatCmd>(&mut self, cmd: &Cmd) -> Result<Cmd::Response, Error> { | ^^^ has type `&Cmd` which is not `Send`, because `Cmd` is not `Sync` = note: `Cmd` doesn't implement `core::marker::Sync` note: captured value is not `Send` because `&mut` references cannot be sent unless their referent is `Send` --> atat/src/asynch/mod.rs:43:33 | 43 | async fn send<Cmd: AtatCmd>(&mut self, cmd: &Cmd) -> Result<Cmd::Response, Error> { | ^^^^^^^^^ has type `&mut &mut T` which is not `Send`, because `&mut T` is not `Send` = note: `T` doesn't implement `core::marker::Send` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#future_not_send
T::send(self, cmd).await
}
}
16 changes: 8 additions & 8 deletions atat/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ pub type GetTimeout = fn(Instant, Duration) -> Instant;

impl Default for Config {
fn default() -> Self {
Self {
cmd_cooldown: Duration::from_millis(20),
tx_timeout: Duration::from_millis(1000),
flush_timeout: Duration::from_millis(1000),
get_response_timeout,
}
Self::new()
}
}

Expand All @@ -32,8 +27,13 @@ fn get_response_timeout(start: Instant, duration: Duration) -> Instant {

impl Config {
#[must_use]
pub fn new() -> Self {
Self::default()
pub const fn new() -> Self {
Self {
cmd_cooldown: Duration::from_millis(20),
tx_timeout: Duration::from_millis(1000),
flush_timeout: Duration::from_millis(1000),
get_response_timeout,
}
}

#[must_use]
Expand Down

0 comments on commit a466836

Please sign in to comment.