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.
pub trait EndpointError: OutgoingResponse + StdError + Sized + 'static {
pub trait EndpointError: OutgoingResponse + StdError + Sized + Send + 'static {
/// Tries to construct `Self` from an `http::Response`.
///
/// 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,
access_token: SendAccessToken<'_>,
request: R,
) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>>
where
<R as OutgoingRequest>::EndpointError: Send,
{
) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>> {
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>>
where
R: OutgoingRequest + 'a,
<R as OutgoingRequest>::EndpointError: Send,
F: FnOnce(&mut http::Request<Self::RequestBody>) -> Result<(), ResponseError<Self, R>> + 'a,
{
Box::pin(crate::send_customized_request(
@ -103,10 +99,7 @@ pub trait HttpClientExt: HttpClient {
access_token: SendAccessToken<'_>,
user_id: &'a UserId,
request: R,
) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>>
where
<R as OutgoingRequest>::EndpointError: Send,
{
) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>> {
self.send_customized_request(
homeserver_url,
access_token,

View File

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