From 0b2a4594002e0e8c42b38d215dbc4d5190f4a252 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 10 Jan 2024 16:31:25 +0100 Subject: [PATCH] client: Replace async-trait with RPITIT / AFIT (return type position impl trait in traits / async fn in traits) --- .github/workflows/ci.yml | 8 ++++---- Cargo.toml | 2 +- README.md | 2 +- crates/ruma-client/Cargo.toml | 1 - crates/ruma-client/src/http_client.rs | 8 ++------ crates/ruma-client/src/http_client/hyper.rs | 2 -- crates/ruma-client/src/http_client/isahc.rs | 2 -- crates/ruma-client/src/http_client/reqwest.rs | 2 -- crates/ruma/CHANGELOG.md | 2 ++ xtask/src/ci.rs | 2 +- 10 files changed, 11 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6391d6a..ca6737da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: run: target/debug/xtask ci lint msrv: - name: Rust 1.70 / ${{ matrix.name }} + name: Rust 1.75 / ${{ matrix.name }} needs: xtask runs-on: ubuntu-latest strategy: @@ -92,17 +92,17 @@ jobs: - name: Checkout repo uses: actions/checkout@v3 - - name: Install rust 1.70 toolchain + - name: Install rust 1.75 toolchain uses: dtolnay/rust-toolchain@master with: - toolchain: "1.70" + toolchain: "1.75" - uses: Swatinem/rust-cache@v2 with: # A stable compiler update should automatically not reuse old caches. # Add the MSRV as a stable cache key too so bumping it also gets us a # fresh cache. - shared-key: msrv1.70 + shared-key: msrv1.75 - name: Get xtask uses: actions/cache@v3 diff --git a/Cargo.toml b/Cargo.toml index d96f13e4..baa83c00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ default-members = ["crates/*"] resolver = "2" [workspace.package] -rust-version = "1.70" +rust-version = "1.75" [workspace.dependencies] as_variant = "1.2.0" diff --git a/README.md b/README.md index 50542bf2..91bceeed 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md). ## Minimum Rust version -Ruma currently requires Rust 1.70. In general, we will never require beta or +Ruma currently requires Rust 1.75. In general, we will never require beta or nightly for crates.io releases of our crates, and we will try to avoid releasing crates that depend on features that were only just stabilized. diff --git a/crates/ruma-client/Cargo.toml b/crates/ruma-client/Cargo.toml index 66cd0b06..ed7e9ad9 100644 --- a/crates/ruma-client/Cargo.toml +++ b/crates/ruma-client/Cargo.toml @@ -34,7 +34,6 @@ reqwest-rustls-native-roots = ["reqwest", "reqwest?/rustls-tls-native-roots"] [dependencies] assign = { workspace = true } async-stream = "0.3.0" -async-trait = "0.1.50" bytes = "1.0.1" futures-core = "0.3.8" futures-lite = { version = "1.11.3", optional = true } diff --git a/crates/ruma-client/src/http_client.rs b/crates/ruma-client/src/http_client.rs index 834a9548..6c172807 100644 --- a/crates/ruma-client/src/http_client.rs +++ b/crates/ruma-client/src/http_client.rs @@ -3,7 +3,6 @@ use std::{future::Future, pin::Pin}; -use async_trait::async_trait; use bytes::BufMut; use ruma_common::{ api::{MatrixVersion, OutgoingRequest, SendAccessToken}, @@ -31,7 +30,6 @@ pub use self::isahc::Isahc; pub use self::reqwest::Reqwest; /// An HTTP client that can be used to send requests to a Matrix homeserver. -#[async_trait] pub trait HttpClient: Sync { /// The type to use for `try_into_http_request`. type RequestBody: Default + BufMut + Send; @@ -43,10 +41,10 @@ pub trait HttpClient: Sync { type Error: Send + Unpin; /// Send an `http::Request` to get back an `http::Response`. - async fn send_http_request( + fn send_http_request( &self, req: http::Request, - ) -> Result, Self::Error>; + ) -> impl Future, Self::Error>> + Send; } /// An HTTP client that has a default configuration. @@ -126,7 +124,6 @@ pub trait HttpClientExt: HttpClient { } } -#[async_trait] impl HttpClientExt for T {} #[doc(hidden)] @@ -134,7 +131,6 @@ impl HttpClientExt for T {} #[allow(clippy::exhaustive_structs)] pub struct Dummy; -#[async_trait] impl HttpClient for Dummy { type RequestBody = Vec; type ResponseBody = Vec; diff --git a/crates/ruma-client/src/http_client/hyper.rs b/crates/ruma-client/src/http_client/hyper.rs index ed0900b9..55f497d7 100644 --- a/crates/ruma-client/src/http_client/hyper.rs +++ b/crates/ruma-client/src/http_client/hyper.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use bytes::{Bytes, BytesMut}; use hyper::client::{connect::Connect, HttpConnector}; @@ -20,7 +19,6 @@ pub type HyperNativeTls = hyper::Client #[cfg(feature = "hyper-rustls")] pub type HyperRustls = hyper::Client>; -#[async_trait] impl HttpClient for hyper::Client where C: Connect + Clone + Send + Sync + 'static, diff --git a/crates/ruma-client/src/http_client/isahc.rs b/crates/ruma-client/src/http_client/isahc.rs index c607d772..ef8cd60f 100644 --- a/crates/ruma-client/src/http_client/isahc.rs +++ b/crates/ruma-client/src/http_client/isahc.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use futures_lite::AsyncReadExt; use super::HttpClient; @@ -6,7 +5,6 @@ use super::HttpClient; /// The `isahc` crate's `HttpClient`. pub type Isahc = isahc::HttpClient; -#[async_trait] impl HttpClient for Isahc { type RequestBody = Vec; type ResponseBody = Vec; diff --git a/crates/ruma-client/src/http_client/reqwest.rs b/crates/ruma-client/src/http_client/reqwest.rs index 84293dd6..2877daa9 100644 --- a/crates/ruma-client/src/http_client/reqwest.rs +++ b/crates/ruma-client/src/http_client/reqwest.rs @@ -1,6 +1,5 @@ use std::mem; -use async_trait::async_trait; use bytes::{Bytes, BytesMut}; use super::{DefaultConstructibleHttpClient, HttpClient}; @@ -8,7 +7,6 @@ use super::{DefaultConstructibleHttpClient, HttpClient}; /// The `reqwest` crate's `Client`. pub type Reqwest = reqwest::Client; -#[async_trait] impl HttpClient for Reqwest { type RequestBody = BytesMut; type ResponseBody = Bytes; diff --git a/crates/ruma/CHANGELOG.md b/crates/ruma/CHANGELOG.md index 77dd1a2c..cd21da8d 100644 --- a/crates/ruma/CHANGELOG.md +++ b/crates/ruma/CHANGELOG.md @@ -1,5 +1,7 @@ # [unreleased] +- Bump MSRV to 1.75 + # 0.9.4 Upgrade `ruma-events` and re-export its new `unstable-msc4075` feature. diff --git a/xtask/src/ci.rs b/xtask/src/ci.rs index 50465320..52df38bf 100644 --- a/xtask/src/ci.rs +++ b/xtask/src/ci.rs @@ -12,7 +12,7 @@ mod spec_links; use spec_links::check_spec_links; -const MSRV: &str = "1.70"; +const MSRV: &str = "1.75"; #[derive(Args)] pub struct CiArgs {