From 2548e33cbd8efc39d2c2b4f627cd4aacfb2cac16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Fri, 6 Mar 2026 11:35:47 +0300 Subject: [PATCH 1/2] Switch to futures::io traits from tokio Switch async traits to futures::io and add tokio-util compat adapter. This decouples the async interface from tokio to allow other executors to work with AsyncPeekReader and core read/write functions while keeping existing tokio connections unchanged. --- mavlink-core/Cargo.toml | 5 +- .../src/async_connection/direct_serial.rs | 9 ++-- mavlink-core/src/async_connection/file.rs | 5 +- mavlink-core/src/async_connection/tcp.rs | 14 ++--- mavlink-core/src/async_connection/udp.rs | 38 +++++--------- mavlink-core/src/async_peek_reader.rs | 26 +++++----- mavlink-core/src/lib.rs | 52 +++++++++---------- 7 files changed, 71 insertions(+), 78 deletions(-) diff --git a/mavlink-core/Cargo.toml b/mavlink-core/Cargo.toml index d2fa5ee4fc6..992b1350382 100644 --- a/mavlink-core/Cargo.toml +++ b/mavlink-core/Cargo.toml @@ -26,7 +26,7 @@ crc-any = { workspace = true, default-features = false } embedded-hal-02 = { version = "0.2", optional = true, package = "embedded-hal" } embedded-io = { version = "0.7", optional = true } embedded-io-async = { version = "0.7", optional = true } -futures = { version = "0.3", default-features = false, optional = true } +futures = { version = "0.3", default-features = false, features = ["std"], optional = true } nb = { version = "1.0", optional = true } rand = { version = "0.9", optional = true, default-features = false, features = ["std", "std_rng"] } serde = { version = "1.0.115", optional = true, features = ["derive"] } @@ -35,6 +35,7 @@ serialport = { version = "4.7.2", default-features = false, optional = true } sha2 = { version = "0.10", optional = true } tokio = { version = "1.0", default-features = false, features = ["io-util", "net", "fs"], optional = true } tokio-serial = { version = "5.4.4", default-features = false, optional = true } +tokio-util = { version = "0.7", default-features = false, features = ["compat"], optional = true } [features] default = ["std", "tcp", "udp", "direct-serial", "serde"] @@ -49,7 +50,7 @@ direct-serial = ["serialport"] embedded = ["dep:embedded-io", "dep:embedded-io-async"] embedded-hal-02 = ["dep:nb", "dep:embedded-hal-02"] serde = ["dep:serde", "dep:serde_arrays"] -tokio-1 = ["dep:tokio", "dep:async-trait", "dep:tokio-serial", "dep:futures"] +tokio-1 = ["dep:tokio", "dep:async-trait", "dep:tokio-serial", "dep:futures", "dep:tokio-util"] signing = ["dep:sha2"] arbitrary = ["dep:arbitrary", "dep:rand"] diff --git a/mavlink-core/src/async_connection/direct_serial.rs b/mavlink-core/src/async_connection/direct_serial.rs index e508c937459..c29556e7ea0 100644 --- a/mavlink-core/src/async_connection/direct_serial.rs +++ b/mavlink-core/src/async_connection/direct_serial.rs @@ -8,6 +8,7 @@ use async_trait::async_trait; use futures::lock::Mutex; use tokio::io::{BufReader, ReadHalf, WriteHalf}; use tokio_serial::{SerialPort, SerialPortBuilderExt, SerialStream}; +use tokio_util::compat::{Compat, TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt}; use super::AsyncConnectable; use crate::connection::direct_serial::config::SerialConfig; @@ -28,8 +29,8 @@ use crate::{ use super::AsyncMavConnection; pub struct AsyncSerialConnection { - read_port: Mutex>>>, - write_port: Mutex>, + read_port: Mutex>>>>, + write_port: Mutex>>, sequence: AtomicU8, protocol_version: MavlinkVersion, recv_any_version: bool, @@ -187,8 +188,8 @@ impl AsyncConnectable for SerialConfig { let buf_reader = BufReader::with_capacity(read_buffer_capacity, reader); Ok(Box::new(AsyncSerialConnection { - read_port: Mutex::new(AsyncPeekReader::new(buf_reader)), - write_port: Mutex::new(writer), + read_port: Mutex::new(AsyncPeekReader::new(buf_reader.compat())), + write_port: Mutex::new(writer.compat_write()), sequence: AtomicU8::new(0), protocol_version: MavlinkVersion::V2, recv_any_version: false, diff --git a/mavlink-core/src/async_connection/file.rs b/mavlink-core/src/async_connection/file.rs index 365d086e661..297b37d25f6 100644 --- a/mavlink-core/src/async_connection/file.rs +++ b/mavlink-core/src/async_connection/file.rs @@ -14,6 +14,7 @@ use crate::{ use async_trait::async_trait; use futures::lock::Mutex; use tokio::fs::File; +use tokio_util::compat::{Compat, TokioAsyncReadCompatExt}; #[cfg(not(feature = "signing"))] use crate::{read_versioned_msg_async, read_versioned_raw_message_async}; @@ -27,7 +28,7 @@ use crate::{ pub async fn open(file_path: &PathBuf) -> io::Result { let file = File::open(file_path).await?; Ok(AsyncFileConnection { - file: Mutex::new(AsyncPeekReader::new(file)), + file: Mutex::new(AsyncPeekReader::new(file.compat())), protocol_version: MavlinkVersion::V2, recv_any_version: false, #[cfg(feature = "signing")] @@ -36,7 +37,7 @@ pub async fn open(file_path: &PathBuf) -> io::Result { } pub struct AsyncFileConnection { - file: Mutex>, + file: Mutex>>, protocol_version: MavlinkVersion, recv_any_version: bool, #[cfg(feature = "signing")] diff --git a/mavlink-core/src/async_connection/tcp.rs b/mavlink-core/src/async_connection/tcp.rs index aa0a9c094c1..86926829e04 100644 --- a/mavlink-core/src/async_connection/tcp.rs +++ b/mavlink-core/src/async_connection/tcp.rs @@ -12,6 +12,8 @@ use core::ops::DerefMut; use futures::{lock::Mutex, FutureExt}; use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf}; use tokio::net::{TcpListener, TcpStream}; +use tokio_util::compat::Compat; +use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt}; #[cfg(not(feature = "signing"))] use crate::{ @@ -31,9 +33,9 @@ pub async fn tcpout(address: T) -> io::Result(address: T) -> io::Result { let (reader, writer) = socket.into_split(); return Ok(AsyncTcpConnection { - reader: Mutex::new(AsyncPeekReader::new(reader)), + reader: Mutex::new(AsyncPeekReader::new(reader.compat())), writer: Mutex::new(TcpWrite { - socket: writer, + socket: writer.compat_write(), sequence: 0, }), protocol_version: MavlinkVersion::V2, @@ -75,7 +77,7 @@ pub async fn tcpin(address: T) -> io::Result>, + reader: Mutex>>, writer: Mutex, protocol_version: MavlinkVersion, recv_any_version: bool, @@ -84,7 +86,7 @@ pub struct AsyncTcpConnection { } struct TcpWrite { - socket: OwnedWriteHalf, + socket: Compat, sequence: u8, } diff --git a/mavlink-core/src/async_connection/udp.rs b/mavlink-core/src/async_connection/udp.rs index f3c66c1f9b8..ae2ce488b41 100644 --- a/mavlink-core/src/async_connection/udp.rs +++ b/mavlink-core/src/async_connection/udp.rs @@ -5,11 +5,9 @@ use std::io; use std::{collections::VecDeque, io::Read, sync::Arc}; use async_trait::async_trait; +use futures::io::AsyncRead; use futures::lock::Mutex; -use tokio::{ - io::{AsyncRead, ReadBuf}, - net::UdpSocket, -}; +use tokio::net::UdpSocket; use crate::connection::udp::config::{UdpConfig, UdpMode}; use crate::MAVLinkMessageRaw; @@ -38,36 +36,26 @@ impl AsyncRead for UdpRead { fn poll_read( mut self: core::pin::Pin<&mut Self>, cx: &mut core::task::Context<'_>, - buf: &mut ReadBuf<'_>, - ) -> Poll> { + buf: &mut [u8], + ) -> Poll> { if self.buffer.is_empty() { let mut read_buffer = [0u8; MTU_SIZE]; - let mut read_buffer = ReadBuf::new(&mut read_buffer); + let mut read_buf = tokio::io::ReadBuf::new(&mut read_buffer); - match self.socket.poll_recv_from(cx, &mut read_buffer) { + match self.socket.poll_recv_from(cx, &mut read_buf) { Poll::Ready(Ok(address)) => { - let n_buffer = read_buffer.filled().len(); - - let n = (&read_buffer.filled()[0..n_buffer]).read(buf.initialize_unfilled())?; - buf.advance(n); - - self.buffer.extend(&read_buffer.filled()[n..n_buffer]); + let filled = read_buf.filled(); + let n = (&filled[..]).read(buf)?; + self.buffer.extend(&filled[n..]); self.last_recv_address = Some(address); - Poll::Ready(Ok(())) + Poll::Ready(Ok(n)) } Poll::Ready(Err(err)) => Poll::Ready(Err(err)), Poll::Pending => Poll::Pending, } } else { - let read_result = self.buffer.read(buf.initialize_unfilled()); - let result = match read_result { - Ok(n) => { - buf.advance(n); - Ok(()) - } - Err(err) => Err(err), - }; - Poll::Ready(result) + let n = self.buffer.read(buf)?; + Poll::Ready(Ok(n)) } } } @@ -278,7 +266,7 @@ impl AsyncConnectable for UdpConfig { #[cfg(test)] mod tests { use super::*; - use tokio::io::AsyncReadExt; + use futures::io::AsyncReadExt; #[tokio::test] async fn test_datagram_buffering() { diff --git a/mavlink-core/src/async_peek_reader.rs b/mavlink-core/src/async_peek_reader.rs index b1f3e828943..6166656e87e 100644 --- a/mavlink-core/src/async_peek_reader.rs +++ b/mavlink-core/src/async_peek_reader.rs @@ -3,26 +3,26 @@ //! The purpose of the buffered/peekable reader is to allow for backtracking parsers. //! //! This is the async version of [`crate::peek_reader::PeekReader`]. -//! A reader implementing the tokio library's [`tokio::io::AsyncBufRead`]/[`tokio::io::AsyncBufReadExt`] traits seems like a good fit, but +//! A reader implementing the [`futures::io::AsyncBufRead`]/[`futures::io::AsyncBufReadExt`] traits seems like a good fit, but //! it does not allow for peeking a specific number of bytes, so it provides no way to request //! more data from the underlying reader without consuming the existing data. //! -//! This API still tries to adhere to the [`tokio::io::AsyncBufRead`]'s trait philosophy. +//! This API still tries to adhere to the [`futures::io::AsyncBufRead`]'s trait philosophy. //! -//! The main type [`AsyncPeekReader`] does not implement [`tokio::io::AsyncBufReadExt`] itself, as there is no added benefit +//! The main type [`AsyncPeekReader`] does not implement [`futures::io::AsyncBufReadExt`] itself, as there is no added benefit //! in doing so. //! #[cfg(doc)] use std::io::ErrorKind; -use tokio::io::AsyncReadExt; +use futures::io::AsyncReadExt; use crate::error::MessageReadError; /// A buffered/peekable reader /// -/// This reader wraps a type implementing [`tokio::io::AsyncRead`] and adds buffering via an internal buffer. +/// This reader wraps a type implementing [`futures::io::AsyncRead`] and adds buffering via an internal buffer. /// /// It allows the user to `peek` a specified number of bytes (without consuming them), /// to `read` bytes (consuming them), or to `consume` them after `peek`ing. @@ -41,8 +41,8 @@ pub struct AsyncPeekReader { reader: R, } -impl AsyncPeekReader { - /// Instantiates a new [`AsyncPeekReader`], wrapping the provided [`tokio::io::AsyncReadExt`] and using the default chunk size +impl AsyncPeekReader { + /// Instantiates a new [`AsyncPeekReader`], wrapping the provided [`futures::io::AsyncRead`] and using the default chunk size pub fn new(reader: R) -> Self { Self { buffer: [0; BUFFER_SIZE], @@ -55,14 +55,14 @@ impl AsyncPeekReader AsyncPeekReader AsyncPeekReader &R { &self.reader } - /// Returns a mutable reference to the underlying [`tokio::io::AsyncRead`] + /// Returns a mutable reference to the underlying [`futures::io::AsyncRead`] /// /// Reading directly from the underlying reader will cause data loss pub fn reader_mut(&mut self) -> &mut R { diff --git a/mavlink-core/src/lib.rs b/mavlink-core/src/lib.rs index dbe5ed5c1f7..dae43b29441 100644 --- a/mavlink-core/src/lib.rs +++ b/mavlink-core/src/lib.rs @@ -62,7 +62,7 @@ //! - `v2` functions write messages using MAVLink 2 serialisation //! - `versioned` functions write messages using the version specified in an aditional `version` parameter //! - `_async` functions, which are only enabled with the `tokio-1` feature, are -//! [async](https://doc.rust-lang.org/std/keyword.async.html) and write from an [`tokio::io::AsyncWrite`]r instead. +//! [async](https://doc.rust-lang.org/std/keyword.async.html) and write to a [`futures::io::AsyncWrite`]r instead. //! - `_signed` functions, which are only enabled with the `signing` feature, have an `Option<&SigningData>` parameter that allows the use of MAVLink 2 message signing. //! //! ## Write errors @@ -76,8 +76,8 @@ //! [`PeekReader`]: peek_reader::PeekReader //! [`AsyncPeekReader`]: async_peek_reader::AsyncPeekReader //! [`UnexpectedEof`]: std::io::ErrorKind::UnexpectedEof -//! [`AsyncRead`]: tokio::io::AsyncRead -//! [`AsyncWrite`]: tokio::io::AsyncWrite +//! [`AsyncRead`]: futures::io::AsyncRead +//! [`AsyncWrite`]: futures::io::AsyncWrite //! [`Interrupted`]: std::io::ErrorKind::Interrupted #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(docsrs, feature(doc_cfg))] @@ -127,7 +127,7 @@ pub mod async_peek_reader; #[cfg(feature = "tokio-1")] use async_peek_reader::AsyncPeekReader; #[cfg(feature = "tokio-1")] -use tokio::io::{AsyncWrite, AsyncWriteExt}; +use futures::io::{AsyncWrite, AsyncWriteExt}; #[cfg(any(feature = "embedded", feature = "embedded-hal-02"))] pub mod embedded; @@ -478,7 +478,7 @@ pub fn read_versioned_raw_message( /// /// See [`read_` function error documentation](crate#read-errors) #[cfg(feature = "tokio-1")] -pub async fn read_versioned_msg_async( +pub async fn read_versioned_msg_async( r: &mut AsyncPeekReader, version: ReadVersion, ) -> Result<(MavHeader, M), MessageReadError> { @@ -495,7 +495,7 @@ pub async fn read_versioned_msg_async( +pub async fn read_versioned_raw_message_async( r: &mut AsyncPeekReader, version: ReadVersion, ) -> Result { @@ -567,7 +567,7 @@ pub fn read_versioned_msg_signed( #[cfg(all(feature = "tokio-1", feature = "signing"))] pub async fn read_versioned_raw_message_async_signed< M: Message, - R: tokio::io::AsyncRead + Unpin, + R: futures::io::AsyncRead + Unpin, >( r: &mut AsyncPeekReader, version: ReadVersion, @@ -593,7 +593,7 @@ pub async fn read_versioned_raw_message_async_signed< /// /// See [`read_` function error documentation](crate#read-errors) #[cfg(all(feature = "tokio-1", feature = "signing"))] -pub async fn read_versioned_msg_async_signed( +pub async fn read_versioned_msg_async_signed( r: &mut AsyncPeekReader, version: ReadVersion, signing_data: Option<&SigningData>, @@ -819,7 +819,7 @@ fn try_decode_v1( #[cfg(feature = "tokio-1")] // other then the blocking version the STX is read not peeked, this changed some sizes -async fn try_decode_v1_async( +async fn try_decode_v1_async( reader: &mut AsyncPeekReader, ) -> Result, MessageReadError> { let mut message = MAVLinkV1MessageRaw::new(); @@ -873,7 +873,7 @@ pub fn read_v1_raw_message( /// /// See [`read_` function error documentation](crate#read-errors) #[cfg(feature = "tokio-1")] -pub async fn read_v1_raw_message_async( +pub async fn read_v1_raw_message_async( reader: &mut AsyncPeekReader, ) -> Result { loop { @@ -963,7 +963,7 @@ pub fn read_v1_msg( /// /// See [`read_` function error documentation](crate#read-errors) #[cfg(feature = "tokio-1")] -pub async fn read_v1_msg_async( +pub async fn read_v1_msg_async( r: &mut AsyncPeekReader, ) -> Result<(MavHeader, M), MessageReadError> { let message = read_v1_raw_message_async::(r).await?; @@ -1394,7 +1394,7 @@ fn try_decode_v2( #[cfg(feature = "tokio-1")] #[allow(unused_variables)] // other then the blocking version the STX is read not peeked, this changed some sizes -async fn try_decode_v2_async( +async fn try_decode_v2_async( reader: &mut AsyncPeekReader, signing_data: Option<&SigningData>, ) -> Result, MessageReadError> { @@ -1483,7 +1483,7 @@ fn read_v2_raw_message_inner( /// /// See [`read_` function error documentation](crate#read-errors) #[cfg(feature = "tokio-1")] -pub async fn read_v2_raw_message_async( +pub async fn read_v2_raw_message_async( reader: &mut AsyncPeekReader, ) -> Result { read_v2_raw_message_async_inner::(reader, None).await @@ -1491,7 +1491,7 @@ pub async fn read_v2_raw_message_async( +async fn read_v2_raw_message_async_inner( reader: &mut AsyncPeekReader, signing_data: Option<&SigningData>, ) -> Result { @@ -1515,7 +1515,7 @@ async fn read_v2_raw_message_async_inner( +pub async fn read_v2_raw_message_async_signed( reader: &mut AsyncPeekReader, signing_data: Option<&SigningData>, ) -> Result { @@ -1618,7 +1618,7 @@ fn read_v2_msg_inner( /// /// See [`read_` function error documentation](crate#read-errors) #[cfg(feature = "tokio-1")] -pub async fn read_v2_msg_async( +pub async fn read_v2_msg_async( read: &mut AsyncPeekReader, ) -> Result<(MavHeader, M), MessageReadError> { read_v2_msg_async_inner(read, None).await @@ -1630,7 +1630,7 @@ pub async fn read_v2_msg_async( /// /// See [`read_` function error documentation](crate#read-errors) #[cfg(all(feature = "tokio-1", feature = "signing"))] -pub async fn read_v2_msg_async_signed( +pub async fn read_v2_msg_async_signed( read: &mut AsyncPeekReader, signing_data: Option<&SigningData>, ) -> Result<(MavHeader, M), MessageReadError> { @@ -1638,7 +1638,7 @@ pub async fn read_v2_msg_async_signed( +async fn read_v2_msg_async_inner( read: &mut AsyncPeekReader, signing_data: Option<&SigningData>, ) -> Result<(MavHeader, M), MessageReadError> { @@ -1799,7 +1799,7 @@ fn read_any_raw_message_inner( /// /// See [`read_` function error documentation](crate#read-errors) #[cfg(feature = "tokio-1")] -pub async fn read_any_raw_message_async( +pub async fn read_any_raw_message_async( reader: &mut AsyncPeekReader, ) -> Result { read_any_raw_message_async_inner::(reader, None).await @@ -1813,7 +1813,7 @@ pub async fn read_any_raw_message_async( +pub async fn read_any_raw_message_async_signed( reader: &mut AsyncPeekReader, signing_data: Option<&SigningData>, ) -> Result { @@ -1822,7 +1822,7 @@ pub async fn read_any_raw_message_async_signed( +async fn read_any_raw_message_async_inner( reader: &mut AsyncPeekReader, signing_data: Option<&SigningData>, ) -> Result { @@ -1912,7 +1912,7 @@ fn read_any_msg_inner( /// /// See [`read_` function error documentation](crate#read-errors) #[cfg(feature = "tokio-1")] -pub async fn read_any_msg_async( +pub async fn read_any_msg_async( read: &mut AsyncPeekReader, ) -> Result<(MavHeader, M), MessageReadError> { read_any_msg_async_inner(read, None).await @@ -1927,7 +1927,7 @@ pub async fn read_any_msg_async( /// See [`read_` function error documentation](crate#read-errors) #[cfg(all(feature = "tokio-1", feature = "signing"))] #[inline] -pub async fn read_any_msg_async_signed( +pub async fn read_any_msg_async_signed( read: &mut AsyncPeekReader, signing_data: Option<&SigningData>, ) -> Result<(MavHeader, M), MessageReadError> { @@ -1935,7 +1935,7 @@ pub async fn read_any_msg_async_signed( +async fn read_any_msg_async_inner( read: &mut AsyncPeekReader, signing_data: Option<&SigningData>, ) -> Result<(MavHeader, M), MessageReadError> { @@ -2273,7 +2273,7 @@ pub fn read_raw_versioned_msg( #[cfg(feature = "tokio-1")] #[deprecated = "use read_versioned_raw_message_async instead"] -pub async fn read_raw_versioned_msg_async( +pub async fn read_raw_versioned_msg_async( r: &mut AsyncPeekReader, version: ReadVersion, ) -> Result { @@ -2292,7 +2292,7 @@ pub fn read_raw_versioned_msg_signed( #[cfg(all(feature = "tokio-1", feature = "signing"))] #[deprecated = "use read_versioned_raw_message_async_signed instead"] -pub async fn read_raw_versioned_msg_async_signed( +pub async fn read_raw_versioned_msg_async_signed( r: &mut AsyncPeekReader, version: ReadVersion, signing_data: Option<&SigningData>, From e6d4b25a7cd70fc7035f64e2f15e3c3774810f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Fri, 6 Mar 2026 11:47:51 +0300 Subject: [PATCH 2/2] bless clippy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onur Özkan --- mavlink-core/src/async_connection/direct_serial.rs | 12 ++++-------- mavlink-core/src/async_connection/file.rs | 12 ++++-------- mavlink-core/src/connection/direct_serial.rs | 12 ++++-------- mavlink-core/src/connection/file.rs | 12 ++++-------- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/mavlink-core/src/async_connection/direct_serial.rs b/mavlink-core/src/async_connection/direct_serial.rs index c29556e7ea0..6978abf0aa5 100644 --- a/mavlink-core/src/async_connection/direct_serial.rs +++ b/mavlink-core/src/async_connection/direct_serial.rs @@ -55,10 +55,8 @@ impl AsyncMavConnection for AsyncSerialConnection { .await; match result { Ok(message) => return Ok(message), - Err(MessageReadError::Io(e)) => { - if e.kind() == io::ErrorKind::UnexpectedEof { - return Err(MessageReadError::Io(e)); - } + Err(MessageReadError::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => { + return Err(MessageReadError::Io(e)); } _ => {} } @@ -80,10 +78,8 @@ impl AsyncMavConnection for AsyncSerialConnection { .await; match result { Ok(message) => return Ok(message), - Err(MessageReadError::Io(e)) => { - if e.kind() == io::ErrorKind::UnexpectedEof { - return Err(MessageReadError::Io(e)); - } + Err(MessageReadError::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => { + return Err(MessageReadError::Io(e)); } _ => {} } diff --git a/mavlink-core/src/async_connection/file.rs b/mavlink-core/src/async_connection/file.rs index 297b37d25f6..92381c5c362 100644 --- a/mavlink-core/src/async_connection/file.rs +++ b/mavlink-core/src/async_connection/file.rs @@ -63,10 +63,8 @@ impl AsyncMavConnection for AsyncFileConnection { ok @ Ok(..) => { return ok; } - Err(MessageReadError::Io(e)) => { - if e.kind() == io::ErrorKind::UnexpectedEof { - return Err(MessageReadError::Io(e)); - } + Err(MessageReadError::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => { + return Err(MessageReadError::Io(e)); } _ => {} } @@ -90,10 +88,8 @@ impl AsyncMavConnection for AsyncFileConnection { ok @ Ok(..) => { return ok; } - Err(MessageReadError::Io(e)) => { - if e.kind() == io::ErrorKind::UnexpectedEof { - return Err(MessageReadError::Io(e)); - } + Err(MessageReadError::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => { + return Err(MessageReadError::Io(e)); } _ => {} } diff --git a/mavlink-core/src/connection/direct_serial.rs b/mavlink-core/src/connection/direct_serial.rs index 5957f7b1cd0..03ecc97b370 100644 --- a/mavlink-core/src/connection/direct_serial.rs +++ b/mavlink-core/src/connection/direct_serial.rs @@ -51,10 +51,8 @@ impl MavConnection for SerialConnection { ok @ Ok(..) => { return ok; } - Err(MessageReadError::Io(e)) => { - if e.kind() == io::ErrorKind::UnexpectedEof { - return Err(MessageReadError::Io(e)); - } + Err(MessageReadError::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => { + return Err(MessageReadError::Io(e)); } _ => {} } @@ -78,10 +76,8 @@ impl MavConnection for SerialConnection { ok @ Ok(..) => { return ok; } - Err(MessageReadError::Io(e)) => { - if e.kind() == io::ErrorKind::UnexpectedEof { - return Err(MessageReadError::Io(e)); - } + Err(MessageReadError::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => { + return Err(MessageReadError::Io(e)); } _ => {} } diff --git a/mavlink-core/src/connection/file.rs b/mavlink-core/src/connection/file.rs index 33fc139b262..65c574a2e31 100644 --- a/mavlink-core/src/connection/file.rs +++ b/mavlink-core/src/connection/file.rs @@ -57,10 +57,8 @@ impl MavConnection for FileConnection { ok @ Ok(..) => { return ok; } - Err(MessageReadError::Io(e)) => { - if e.kind() == io::ErrorKind::UnexpectedEof { - return Err(MessageReadError::Io(e)); - } + Err(MessageReadError::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => { + return Err(MessageReadError::Io(e)); } _ => {} } @@ -84,10 +82,8 @@ impl MavConnection for FileConnection { ok @ Ok(..) => { return ok; } - Err(MessageReadError::Io(e)) => { - if e.kind() == io::ErrorKind::UnexpectedEof { - return Err(MessageReadError::Io(e)); - } + Err(MessageReadError::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => { + return Err(MessageReadError::Io(e)); } _ => {} }