diff --git a/ruma-api-macros/src/api.rs b/ruma-api-macros/src/api.rs index 63a2b173..4bdca48e 100644 --- a/ruma-api-macros/src/api.rs +++ b/ruma-api-macros/src/api.rs @@ -303,6 +303,8 @@ impl ToTokens for Api { impl #request_lifetimes ::ruma_api::Endpoint for Request #request_lifetimes { type Response = Response; type ResponseError = #error; + type IncomingRequest = ::Incoming; + type IncomingResponse = ::Incoming; /// Metadata for the `#name` endpoint. const METADATA: ::ruma_api::Metadata = ::ruma_api::Metadata { diff --git a/ruma-api/src/lib.rs b/ruma-api/src/lib.rs index d4df04bb..3f5f308c 100644 --- a/ruma-api/src/lib.rs +++ b/ruma-api/src/lib.rs @@ -245,19 +245,21 @@ pub trait EndpointError: Sized { /// A Matrix API endpoint. /// /// The type implementing this trait contains any data needed to make a request to the endpoint. -pub trait Endpoint: Outgoing -where - ::Incoming: TryFrom>, Error = FromHttpRequestError>, - ::Incoming: TryFrom< - http::Response>, - Error = FromHttpResponseError<::ResponseError>, - >, -{ +pub trait Endpoint: Outgoing::IncomingRequest> { /// Data returned in a successful response from the endpoint. - type Response: Outgoing + TryInto>, Error = IntoHttpError>; + type Response: Outgoing + + TryInto>, Error = IntoHttpError>; /// Error type returned when response from endpoint fails. type ResponseError: EndpointError; + /// Shorthand for `::Incoming`. + type IncomingRequest: TryFrom>, Error = FromHttpRequestError>; + /// Shorthand for `::Incoming`. + type IncomingResponse: TryFrom< + http::Response>, + Error = FromHttpResponseError<::ResponseError>, + >; + /// Metadata about the endpoint. const METADATA: Metadata; @@ -280,15 +282,7 @@ where /// /// This marker trait is to indicate that a type implementing `Endpoint` doesn't require any /// authentication. -pub trait NonAuthEndpoint: Endpoint -where - ::Incoming: TryFrom>, Error = FromHttpRequestError>, - ::Incoming: TryFrom< - http::Response>, - Error = FromHttpResponseError<::ResponseError>, - >, -{ -} +pub trait NonAuthEndpoint: Endpoint {} /// Metadata about an API endpoint. #[derive(Clone, Debug)] @@ -365,6 +359,8 @@ mod tests { impl Endpoint for Request { type Response = Response; type ResponseError = Void; + type IncomingRequest = Self; + type IncomingResponse = Response; const METADATA: Metadata = Metadata { description: "Add an alias to a room.",