Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(atat): Add blanket impl of AtatClient for mutable reference #208

Merged
merged 1 commit into from
Jul 16, 2024
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
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 @@
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
Loading