Add Endpoint::{IncomingRequest, IncomingResponse}
With these, it is no longer necessary to copy over the Endpoint trait's where clauses whenever it is used as a bound
This commit is contained in:
parent
ddb1b48e71
commit
9cf552f361
@ -303,6 +303,8 @@ impl ToTokens for Api {
|
|||||||
impl #request_lifetimes ::ruma_api::Endpoint for Request #request_lifetimes {
|
impl #request_lifetimes ::ruma_api::Endpoint for Request #request_lifetimes {
|
||||||
type Response = Response;
|
type Response = Response;
|
||||||
type ResponseError = #error;
|
type ResponseError = #error;
|
||||||
|
type IncomingRequest = <Self as ::ruma_api::Outgoing>::Incoming;
|
||||||
|
type IncomingResponse = <Response as ::ruma_api::Outgoing>::Incoming;
|
||||||
|
|
||||||
/// Metadata for the `#name` endpoint.
|
/// Metadata for the `#name` endpoint.
|
||||||
const METADATA: ::ruma_api::Metadata = ::ruma_api::Metadata {
|
const METADATA: ::ruma_api::Metadata = ::ruma_api::Metadata {
|
||||||
|
@ -245,19 +245,21 @@ pub trait EndpointError: Sized {
|
|||||||
/// A Matrix API endpoint.
|
/// A Matrix API endpoint.
|
||||||
///
|
///
|
||||||
/// The type implementing this trait contains any data needed to make a request to the endpoint.
|
/// The type implementing this trait contains any data needed to make a request to the endpoint.
|
||||||
pub trait Endpoint: Outgoing
|
pub trait Endpoint: Outgoing<Incoming = <Self as Endpoint>::IncomingRequest> {
|
||||||
where
|
|
||||||
<Self as Outgoing>::Incoming: TryFrom<http::Request<Vec<u8>>, Error = FromHttpRequestError>,
|
|
||||||
<Self::Response as Outgoing>::Incoming: TryFrom<
|
|
||||||
http::Response<Vec<u8>>,
|
|
||||||
Error = FromHttpResponseError<<Self as Endpoint>::ResponseError>,
|
|
||||||
>,
|
|
||||||
{
|
|
||||||
/// Data returned in a successful response from the endpoint.
|
/// Data returned in a successful response from the endpoint.
|
||||||
type Response: Outgoing + TryInto<http::Response<Vec<u8>>, Error = IntoHttpError>;
|
type Response: Outgoing<Incoming = Self::IncomingResponse>
|
||||||
|
+ TryInto<http::Response<Vec<u8>>, Error = IntoHttpError>;
|
||||||
/// Error type returned when response from endpoint fails.
|
/// Error type returned when response from endpoint fails.
|
||||||
type ResponseError: EndpointError;
|
type ResponseError: EndpointError;
|
||||||
|
|
||||||
|
/// Shorthand for `<Self as Outgoing>::Incoming`.
|
||||||
|
type IncomingRequest: TryFrom<http::Request<Vec<u8>>, Error = FromHttpRequestError>;
|
||||||
|
/// Shorthand for `<Self::Response as Outgoing>::Incoming`.
|
||||||
|
type IncomingResponse: TryFrom<
|
||||||
|
http::Response<Vec<u8>>,
|
||||||
|
Error = FromHttpResponseError<<Self as Endpoint>::ResponseError>,
|
||||||
|
>;
|
||||||
|
|
||||||
/// Metadata about the endpoint.
|
/// Metadata about the endpoint.
|
||||||
const METADATA: Metadata;
|
const METADATA: Metadata;
|
||||||
|
|
||||||
@ -280,15 +282,7 @@ where
|
|||||||
///
|
///
|
||||||
/// This marker trait is to indicate that a type implementing `Endpoint` doesn't require any
|
/// This marker trait is to indicate that a type implementing `Endpoint` doesn't require any
|
||||||
/// authentication.
|
/// authentication.
|
||||||
pub trait NonAuthEndpoint: Endpoint
|
pub trait NonAuthEndpoint: Endpoint {}
|
||||||
where
|
|
||||||
<Self as Outgoing>::Incoming: TryFrom<http::Request<Vec<u8>>, Error = FromHttpRequestError>,
|
|
||||||
<Self::Response as Outgoing>::Incoming: TryFrom<
|
|
||||||
http::Response<Vec<u8>>,
|
|
||||||
Error = FromHttpResponseError<<Self as Endpoint>::ResponseError>,
|
|
||||||
>,
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Metadata about an API endpoint.
|
/// Metadata about an API endpoint.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -365,6 +359,8 @@ mod tests {
|
|||||||
impl Endpoint for Request {
|
impl Endpoint for Request {
|
||||||
type Response = Response;
|
type Response = Response;
|
||||||
type ResponseError = Void;
|
type ResponseError = Void;
|
||||||
|
type IncomingRequest = Self;
|
||||||
|
type IncomingResponse = Response;
|
||||||
|
|
||||||
const METADATA: Metadata = Metadata {
|
const METADATA: Metadata = Metadata {
|
||||||
description: "Add an alias to a room.",
|
description: "Add an alias to a room.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user