api: Require all EndpointErrors to be Send

This commit is contained in:
Jonas Platte 2021-04-28 14:45:59 +02:00
parent cee6e2e365
commit a2b64df5d3
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
3 changed files with 5 additions and 20 deletions

View File

@ -354,7 +354,7 @@ pub trait OutgoingResponse {
} }
/// Gives users the ability to define their own serializable / deserializable errors. /// Gives users the ability to define their own serializable / deserializable errors.
pub trait EndpointError: OutgoingResponse + StdError + Sized + 'static { pub trait EndpointError: OutgoingResponse + StdError + Sized + Send + 'static {
/// Tries to construct `Self` from an `http::Response`. /// Tries to construct `Self` from an `http::Response`.
/// ///
/// This will always return `Err` variant when no `error` field is defined in /// This will always return `Err` variant when no `error` field is defined in

View File

@ -61,10 +61,7 @@ pub trait HttpClientExt: HttpClient {
homeserver_url: &str, homeserver_url: &str,
access_token: SendAccessToken<'_>, access_token: SendAccessToken<'_>,
request: R, request: R,
) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>> ) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>> {
where
<R as OutgoingRequest>::EndpointError: Send,
{
self.send_customized_request(homeserver_url, access_token, request, |_| Ok(())) self.send_customized_request(homeserver_url, access_token, request, |_| Ok(()))
} }
@ -80,7 +77,6 @@ pub trait HttpClientExt: HttpClient {
) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>> ) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>>
where where
R: OutgoingRequest + 'a, R: OutgoingRequest + 'a,
<R as OutgoingRequest>::EndpointError: Send,
F: FnOnce(&mut http::Request<Self::RequestBody>) -> Result<(), ResponseError<Self, R>> + 'a, F: FnOnce(&mut http::Request<Self::RequestBody>) -> Result<(), ResponseError<Self, R>> + 'a,
{ {
Box::pin(crate::send_customized_request( Box::pin(crate::send_customized_request(
@ -103,10 +99,7 @@ pub trait HttpClientExt: HttpClient {
access_token: SendAccessToken<'_>, access_token: SendAccessToken<'_>,
user_id: &'a UserId, user_id: &'a UserId,
request: R, request: R,
) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>> ) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>> {
where
<R as OutgoingRequest>::EndpointError: Send,
{
self.send_customized_request( self.send_customized_request(
homeserver_url, homeserver_url,
access_token, access_token,

View File

@ -158,10 +158,7 @@ impl<C: DefaultConstructibleHttpClient> Client<C> {
impl<C: HttpClient> Client<C> { impl<C: HttpClient> Client<C> {
/// Makes a request to a Matrix API endpoint. /// Makes a request to a Matrix API endpoint.
pub async fn send_request<R: OutgoingRequest>(&self, request: R) -> ResponseResult<C, R> pub async fn send_request<R: OutgoingRequest>(&self, request: R) -> ResponseResult<C, R> {
where
<R as OutgoingRequest>::EndpointError: Send,
{
self.send_customized_request(request, |_| Ok(())).await self.send_customized_request(request, |_| Ok(())).await
} }
@ -173,7 +170,6 @@ impl<C: HttpClient> Client<C> {
) -> ResponseResult<C, R> ) -> ResponseResult<C, R>
where where
R: OutgoingRequest, R: OutgoingRequest,
<R as OutgoingRequest>::EndpointError: Send,
F: FnOnce(&mut http::Request<C::RequestBody>) -> Result<(), ResponseError<C, R>>, F: FnOnce(&mut http::Request<C::RequestBody>) -> Result<(), ResponseError<C, R>>,
{ {
let access_token = self.access_token(); let access_token = self.access_token();
@ -200,10 +196,7 @@ impl<C: HttpClient> Client<C> {
&self, &self,
user_id: &UserId, user_id: &UserId,
request: R, request: R,
) -> ResponseResult<C, R> ) -> ResponseResult<C, R> {
where
<R as OutgoingRequest>::EndpointError: Send,
{
self.send_customized_request(request, add_user_id_to_query::<C, R>(user_id)).await self.send_customized_request(request, add_user_id_to_query::<C, R>(user_id)).await
} }
} }
@ -218,7 +211,6 @@ fn send_customized_request<'a, C, R, F>(
where where
C: HttpClient + ?Sized, C: HttpClient + ?Sized,
R: OutgoingRequest, R: OutgoingRequest,
<R as OutgoingRequest>::EndpointError: Send,
F: FnOnce(&mut http::Request<C::RequestBody>) -> Result<(), ResponseError<C, R>>, F: FnOnce(&mut http::Request<C::RequestBody>) -> Result<(), ResponseError<C, R>>,
{ {
let http_req = request let http_req = request