client: Replace async-trait with RPITIT / AFIT

(return type position impl trait in traits / async fn in traits)
This commit is contained in:
Jonas Platte 2024-01-10 16:31:25 +01:00
parent d77c0d0bd7
commit 0b2a459400
10 changed files with 11 additions and 20 deletions

View File

@ -67,7 +67,7 @@ jobs:
run: target/debug/xtask ci lint run: target/debug/xtask ci lint
msrv: msrv:
name: Rust 1.70 / ${{ matrix.name }} name: Rust 1.75 / ${{ matrix.name }}
needs: xtask needs: xtask
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@ -92,17 +92,17 @@ jobs:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install rust 1.70 toolchain - name: Install rust 1.75 toolchain
uses: dtolnay/rust-toolchain@master uses: dtolnay/rust-toolchain@master
with: with:
toolchain: "1.70" toolchain: "1.75"
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
with: with:
# A stable compiler update should automatically not reuse old caches. # 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 # Add the MSRV as a stable cache key too so bumping it also gets us a
# fresh cache. # fresh cache.
shared-key: msrv1.70 shared-key: msrv1.75
- name: Get xtask - name: Get xtask
uses: actions/cache@v3 uses: actions/cache@v3

View File

@ -5,7 +5,7 @@ default-members = ["crates/*"]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
rust-version = "1.70" rust-version = "1.75"
[workspace.dependencies] [workspace.dependencies]
as_variant = "1.2.0" as_variant = "1.2.0"

View File

@ -52,7 +52,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
## Minimum Rust version ## 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 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. crates that depend on features that were only just stabilized.

View File

@ -34,7 +34,6 @@ reqwest-rustls-native-roots = ["reqwest", "reqwest?/rustls-tls-native-roots"]
[dependencies] [dependencies]
assign = { workspace = true } assign = { workspace = true }
async-stream = "0.3.0" async-stream = "0.3.0"
async-trait = "0.1.50"
bytes = "1.0.1" bytes = "1.0.1"
futures-core = "0.3.8" futures-core = "0.3.8"
futures-lite = { version = "1.11.3", optional = true } futures-lite = { version = "1.11.3", optional = true }

View File

@ -3,7 +3,6 @@
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
use async_trait::async_trait;
use bytes::BufMut; use bytes::BufMut;
use ruma_common::{ use ruma_common::{
api::{MatrixVersion, OutgoingRequest, SendAccessToken}, api::{MatrixVersion, OutgoingRequest, SendAccessToken},
@ -31,7 +30,6 @@ pub use self::isahc::Isahc;
pub use self::reqwest::Reqwest; pub use self::reqwest::Reqwest;
/// An HTTP client that can be used to send requests to a Matrix homeserver. /// An HTTP client that can be used to send requests to a Matrix homeserver.
#[async_trait]
pub trait HttpClient: Sync { pub trait HttpClient: Sync {
/// The type to use for `try_into_http_request`. /// The type to use for `try_into_http_request`.
type RequestBody: Default + BufMut + Send; type RequestBody: Default + BufMut + Send;
@ -43,10 +41,10 @@ pub trait HttpClient: Sync {
type Error: Send + Unpin; type Error: Send + Unpin;
/// Send an `http::Request` to get back an `http::Response`. /// Send an `http::Request` to get back an `http::Response`.
async fn send_http_request( fn send_http_request(
&self, &self,
req: http::Request<Self::RequestBody>, req: http::Request<Self::RequestBody>,
) -> Result<http::Response<Self::ResponseBody>, Self::Error>; ) -> impl Future<Output = Result<http::Response<Self::ResponseBody>, Self::Error>> + Send;
} }
/// An HTTP client that has a default configuration. /// An HTTP client that has a default configuration.
@ -126,7 +124,6 @@ pub trait HttpClientExt: HttpClient {
} }
} }
#[async_trait]
impl<T: HttpClient> HttpClientExt for T {} impl<T: HttpClient> HttpClientExt for T {}
#[doc(hidden)] #[doc(hidden)]
@ -134,7 +131,6 @@ impl<T: HttpClient> HttpClientExt for T {}
#[allow(clippy::exhaustive_structs)] #[allow(clippy::exhaustive_structs)]
pub struct Dummy; pub struct Dummy;
#[async_trait]
impl HttpClient for Dummy { impl HttpClient for Dummy {
type RequestBody = Vec<u8>; type RequestBody = Vec<u8>;
type ResponseBody = Vec<u8>; type ResponseBody = Vec<u8>;

View File

@ -1,4 +1,3 @@
use async_trait::async_trait;
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use hyper::client::{connect::Connect, HttpConnector}; use hyper::client::{connect::Connect, HttpConnector};
@ -20,7 +19,6 @@ pub type HyperNativeTls = hyper::Client<hyper_tls::HttpsConnector<HttpConnector>
#[cfg(feature = "hyper-rustls")] #[cfg(feature = "hyper-rustls")]
pub type HyperRustls = hyper::Client<hyper_rustls::HttpsConnector<HttpConnector>>; pub type HyperRustls = hyper::Client<hyper_rustls::HttpsConnector<HttpConnector>>;
#[async_trait]
impl<C> HttpClient for hyper::Client<C> impl<C> HttpClient for hyper::Client<C>
where where
C: Connect + Clone + Send + Sync + 'static, C: Connect + Clone + Send + Sync + 'static,

View File

@ -1,4 +1,3 @@
use async_trait::async_trait;
use futures_lite::AsyncReadExt; use futures_lite::AsyncReadExt;
use super::HttpClient; use super::HttpClient;
@ -6,7 +5,6 @@ use super::HttpClient;
/// The `isahc` crate's `HttpClient`. /// The `isahc` crate's `HttpClient`.
pub type Isahc = isahc::HttpClient; pub type Isahc = isahc::HttpClient;
#[async_trait]
impl HttpClient for Isahc { impl HttpClient for Isahc {
type RequestBody = Vec<u8>; type RequestBody = Vec<u8>;
type ResponseBody = Vec<u8>; type ResponseBody = Vec<u8>;

View File

@ -1,6 +1,5 @@
use std::mem; use std::mem;
use async_trait::async_trait;
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use super::{DefaultConstructibleHttpClient, HttpClient}; use super::{DefaultConstructibleHttpClient, HttpClient};
@ -8,7 +7,6 @@ use super::{DefaultConstructibleHttpClient, HttpClient};
/// The `reqwest` crate's `Client`. /// The `reqwest` crate's `Client`.
pub type Reqwest = reqwest::Client; pub type Reqwest = reqwest::Client;
#[async_trait]
impl HttpClient for Reqwest { impl HttpClient for Reqwest {
type RequestBody = BytesMut; type RequestBody = BytesMut;
type ResponseBody = Bytes; type ResponseBody = Bytes;

View File

@ -1,5 +1,7 @@
# [unreleased] # [unreleased]
- Bump MSRV to 1.75
# 0.9.4 # 0.9.4
Upgrade `ruma-events` and re-export its new `unstable-msc4075` feature. Upgrade `ruma-events` and re-export its new `unstable-msc4075` feature.

View File

@ -12,7 +12,7 @@ mod spec_links;
use spec_links::check_spec_links; use spec_links::check_spec_links;
const MSRV: &str = "1.70"; const MSRV: &str = "1.75";
#[derive(Args)] #[derive(Args)]
pub struct CiArgs { pub struct CiArgs {