diff --git a/Cargo.toml b/Cargo.toml index d1b4a2e..9209b67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reqwless" -version = "0.7.0" +version = "0.8.0" edition = "2021" resolver = "2" description = "HTTP client for embedded devices" @@ -13,10 +13,10 @@ keywords = ["embedded", "async", "http", "no_std"] exclude = [".github"] [dependencies] -buffered-io = { version = "0.3.0", features = ["async"] } -embedded-io = { version = "0.5.0" } -embedded-io-async = { version = "0.5.0" } -embedded-nal-async = "0.5.0" +buffered-io = { version = "0.4.0", features = ["async"] } +embedded-io = { version = "0.6" } +embedded-io-async = { version = "0.6" } +embedded-nal-async = "0.6.0" httparse = { version = "1.8.0", default-features = false } heapless = "0.7" hex = { version = "0.4", default-features = false } @@ -24,7 +24,7 @@ base64 = { version = "0.21.0", default-features = false } rand_core = { version = "0.6", default-features = true } log = { version = "0.4", optional = true } defmt = { version = "0.3", optional = true } -embedded-tls = { version = "0.15", default-features = false, features = [ +embedded-tls = { version = "0.16", default-features = false, features = [ "async", ], optional = true } rand_chacha = { version = "0.3", default-features = false } @@ -35,8 +35,8 @@ hyper = { version = "0.14.23", features = ["full"] } tokio = { version = "1.21.2", features = ["full"] } tokio-rustls = { version = "0.23.4" } futures-util = { version = "0.3" } -embedded-io-async = { version = "0.5", features = ["std"] } -embedded-io-adapters = { version = "0.5", features = ["std", "tokio-1"] } +embedded-io-async = { version = "0.6", features = ["std"] } +embedded-io-adapters = { version = "0.6", features = ["std", "tokio-1"] } rustls-pemfile = "1.0" env_logger = "0.10" log = "0.4" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 244657d..7d77370 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ # Before upgrading check that everything is available on all tier1 targets here: # https://rust-lang.github.io/rustup-components-history [toolchain] -channel = "nightly-2022-11-22" +channel = "nightly-2023-10-02" components = ["clippy"] diff --git a/src/client.rs b/src/client.rs index 1b638b2..f8c203e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -154,6 +154,7 @@ where } /// Represents a HTTP connection that may be encrypted or unencrypted. +#[allow(clippy::large_enum_variant)] pub enum HttpConnection<'m, T> where T: Read + Write, @@ -487,7 +488,7 @@ where } mod buffered_io_adapter { - use embedded_io::{Error as _, ErrorType, ReadExactError, WriteAllError}; + use embedded_io::{Error as _, ErrorType, ReadExactError}; use embedded_io_async::{Read, Write}; pub struct Error(embedded_io::ErrorKind); @@ -504,18 +505,6 @@ mod buffered_io_adapter { } } - impl From> for Error - where - T: embedded_io::Error, - { - fn from(value: WriteAllError) -> Self { - match value { - WriteAllError::WriteZero => Self(embedded_io::ErrorKind::Other), - WriteAllError::Other(e) => Self(e.kind()), - } - } - } - pub struct ConnErrorAdapter(pub C); impl ErrorType for ConnErrorAdapter { @@ -534,11 +523,8 @@ mod buffered_io_adapter { self.0.flush().await.map_err(|e| Error(e.kind())) } - async fn write_all(&mut self, buf: &[u8]) -> Result<(), embedded_io::WriteAllError> { - self.0.write_all(buf).await.map_err(|e| match e { - WriteAllError::WriteZero => WriteAllError::WriteZero, - WriteAllError::Other(e) => WriteAllError::Other(Error(e.kind())), - }) + async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> { + self.0.write_all(buf).await.map_err(|e| Error(e.kind())) } } diff --git a/src/headers.rs b/src/headers.rs index 5b3ab40..78a5e2a 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -81,8 +81,8 @@ impl<'a> TryFrom<&'a [u8]> for KeepAlive { timeout: None, max: None, }; - for part in core::str::from_utf8(from)?.split(",") { - let mut splitted = part.split("=").map(|s| s.trim()); + for part in core::str::from_utf8(from)?.split(',') { + let mut splitted = part.split('=').map(|s| s.trim()); if let (Some(key), Some(value)) = (splitted.next(), splitted.next()) { match key { _ if key.eq_ignore_ascii_case("timeout") => keep_alive.timeout = value.parse().ok(), diff --git a/src/lib.rs b/src/lib.rs index ba49b65..6dd9c71 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,10 @@ #![cfg_attr(not(test), no_std)] -#![feature(impl_trait_projections)] #![feature(async_fn_in_trait)] #![allow(incomplete_features)] #![doc = include_str!("../README.md")] use core::{num::ParseIntError, str::Utf8Error}; -use embedded_io_async::{ReadExactError, WriteAllError}; +use embedded_io_async::ReadExactError; mod fmt; @@ -61,18 +60,6 @@ impl From> for Error { } } -impl From> for Error -where - E: embedded_io::Error, -{ - fn from(value: WriteAllError) -> Self { - match value { - WriteAllError::WriteZero => Error::Network(embedded_io::ErrorKind::Other), - WriteAllError::Other(e) => Error::Network(e.kind()), - } - } -} - #[cfg(feature = "embedded-tls")] impl From for Error { fn from(e: embedded_tls::TlsError) -> Error { diff --git a/src/request.rs b/src/request.rs index 35516bc..9f6b45e 100644 --- a/src/request.rs +++ b/src/request.rs @@ -4,7 +4,7 @@ use crate::Error; use core::fmt::Write as _; use core::mem::size_of; use embedded_io::{Error as _, ErrorType}; -use embedded_io_async::{Write, WriteAllError}; +use embedded_io_async::Write; use heapless::String; /// A read only HTTP request type @@ -169,7 +169,7 @@ where Some(len) => { trace!("Writing not-chunked body"); let mut writer = FixedBodyWriter(c, 0); - body.write(&mut writer).await?; + body.write(&mut writer).await.map_err(to_errorkind)?; if writer.1 != len { return Err(Error::IncorrectBodyWritten); @@ -273,7 +273,7 @@ impl Method { } async fn write_str(c: &mut C, data: &str) -> Result<(), Error> { - c.write_all(data.as_bytes()).await?; + c.write_all(data.as_bytes()).await.map_err(to_errorkind)?; Ok(()) } @@ -297,7 +297,7 @@ pub trait RequestBody { } /// Write the body to the provided writer - async fn write(&self, writer: &mut W) -> Result<(), WriteAllError>; + async fn write(&self, writer: &mut W) -> Result<(), W::Error>; } impl RequestBody for () { @@ -305,7 +305,7 @@ impl RequestBody for () { None } - async fn write(&self, _writer: &mut W) -> Result<(), WriteAllError> { + async fn write(&self, _writer: &mut W) -> Result<(), W::Error> { Ok(()) } } @@ -315,7 +315,7 @@ impl RequestBody for &[u8] { Some(<[u8]>::len(self)) } - async fn write(&self, writer: &mut W) -> Result<(), WriteAllError> { + async fn write(&self, writer: &mut W) -> Result<(), W::Error> { writer.write_all(self).await } } @@ -328,7 +328,7 @@ where self.as_ref().map(|inner| inner.len()).unwrap_or_default() } - async fn write(&self, writer: &mut W) -> Result<(), WriteAllError> { + async fn write(&self, writer: &mut W) -> Result<(), W::Error> { if let Some(inner) = self.as_ref() { inner.write(writer).await } else { @@ -356,7 +356,7 @@ where Ok(written) } - async fn write_all(&mut self, buf: &[u8]) -> Result<(), WriteAllError> { + async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> { self.0.write_all(buf).await?; self.1 += buf.len(); Ok(()) @@ -376,11 +376,8 @@ where type Error = embedded_io::ErrorKind; } -fn to_errorkind(e: WriteAllError) -> embedded_io::ErrorKind { - match e { - WriteAllError::WriteZero => embedded_io::ErrorKind::Other, - WriteAllError::Other(e) => e.kind(), - } +fn to_errorkind(e: E) -> embedded_io::ErrorKind { + e.kind() } impl Write for ChunkedBodyWriter<'_, C> @@ -392,7 +389,7 @@ where Ok(buf.len()) } - async fn write_all(&mut self, buf: &[u8]) -> Result<(), WriteAllError> { + async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> { // Write chunk header let len = buf.len(); let mut hex = [0; 2 * size_of::()]; @@ -469,7 +466,7 @@ mod tests { None // Unknown length: triggers chunked body } - async fn write(&self, writer: &mut W) -> Result<(), WriteAllError> { + async fn write(&self, writer: &mut W) -> Result<(), W::Error> { writer.write_all(self.0).await } } diff --git a/src/response.rs b/src/response.rs index 5bd4736..fe0a33d 100644 --- a/src/response.rs +++ b/src/response.rs @@ -67,7 +67,6 @@ where if parse_status.is_complete() { header_len = parse_status.unwrap(); break; - } else { } } diff --git a/tests/client.rs b/tests/client.rs index 11fc8b5..d284899 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -1,5 +1,4 @@ #![feature(async_fn_in_trait)] -#![feature(impl_trait_projections)] #![allow(incomplete_features)] use embedded_io_adapters::tokio_1::FromTokio; use embedded_nal_async::{AddrType, IpAddr, Ipv4Addr}; @@ -286,7 +285,10 @@ impl embedded_nal_async::TcpConnect for TokioTcp { type Error = std::io::Error; type Connection<'m> = FromTokio; - async fn connect<'m>(&self, remote: embedded_nal_async::SocketAddr) -> Result, Self::Error> { + async fn connect<'m>(&'m self, remote: embedded_nal_async::SocketAddr) -> Result, Self::Error> + where + Self: 'm, + { let ip = match remote { embedded_nal_async::SocketAddr::V4(a) => a.ip().octets().into(), embedded_nal_async::SocketAddr::V6(a) => a.ip().octets().into(),