Introduce client
and server
feature flags for *-api crates
This commit is contained in:
parent
c27e66741a
commit
4d51e98707
@ -267,12 +267,14 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
|||||||
quote! {
|
quote! {
|
||||||
#( #attrs )*
|
#( #attrs )*
|
||||||
#[automatically_derived]
|
#[automatically_derived]
|
||||||
|
#[cfg(feature = "client")]
|
||||||
impl #request_lifetimes #ruma_api::OutgoingNonAuthRequest
|
impl #request_lifetimes #ruma_api::OutgoingNonAuthRequest
|
||||||
for Request #request_lifetimes
|
for Request #request_lifetimes
|
||||||
{}
|
{}
|
||||||
|
|
||||||
#( #attrs )*
|
#( #attrs )*
|
||||||
#[automatically_derived]
|
#[automatically_derived]
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl #ruma_api::IncomingNonAuthRequest for #incoming_request_type {}
|
impl #ruma_api::IncomingNonAuthRequest for #incoming_request_type {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,6 +289,7 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
|||||||
#response_type
|
#response_type
|
||||||
|
|
||||||
#[automatically_derived]
|
#[automatically_derived]
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl ::std::convert::TryFrom<Response> for #http::Response<Vec<u8>> {
|
impl ::std::convert::TryFrom<Response> for #http::Response<Vec<u8>> {
|
||||||
type Error = #ruma_api::error::IntoHttpError;
|
type Error = #ruma_api::error::IntoHttpError;
|
||||||
|
|
||||||
@ -308,6 +311,7 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[automatically_derived]
|
#[automatically_derived]
|
||||||
|
#[cfg(feature = "client")]
|
||||||
impl ::std::convert::TryFrom<#http::Response<Vec<u8>>> for Response {
|
impl ::std::convert::TryFrom<#http::Response<Vec<u8>>> for Response {
|
||||||
type Error = #ruma_api::error::FromHttpResponseError<#error>;
|
type Error = #ruma_api::error::FromHttpResponseError<#error>;
|
||||||
|
|
||||||
@ -344,6 +348,7 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[automatically_derived]
|
#[automatically_derived]
|
||||||
|
#[cfg(feature = "client")]
|
||||||
impl #request_lifetimes #ruma_api::OutgoingRequest for Request #request_lifetimes {
|
impl #request_lifetimes #ruma_api::OutgoingRequest for Request #request_lifetimes {
|
||||||
type EndpointError = #error;
|
type EndpointError = #error;
|
||||||
type IncomingResponse = <Response as #ruma_serde::Outgoing>::Incoming;
|
type IncomingResponse = <Response as #ruma_serde::Outgoing>::Incoming;
|
||||||
@ -386,6 +391,7 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[automatically_derived]
|
#[automatically_derived]
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl #ruma_api::IncomingRequest for #incoming_request_type {
|
impl #ruma_api::IncomingRequest for #incoming_request_type {
|
||||||
type EndpointError = #error;
|
type EndpointError = #error;
|
||||||
type OutgoingResponse = Response;
|
type OutgoingResponse = Response;
|
||||||
|
@ -31,3 +31,9 @@ thiserror = "1.0.23"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
ruma-events = { version = "=0.22.0-alpha.2", path = "../ruma-events" }
|
ruma-events = { version = "=0.22.0-alpha.2", path = "../ruma-events" }
|
||||||
trybuild = "1.0.38"
|
trybuild = "1.0.38"
|
||||||
|
|
||||||
|
# These feature gates exist as a workaround to pass tests.
|
||||||
|
# Any crate that invokes the `ruma-api!` macro should include these features.
|
||||||
|
[features]
|
||||||
|
client = []
|
||||||
|
server = []
|
||||||
|
@ -34,6 +34,7 @@ ruma_api! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "client", feature = "server"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn request_serde() -> Result<(), Box<dyn std::error::Error + 'static>> {
|
fn request_serde() -> Result<(), Box<dyn std::error::Error + 'static>> {
|
||||||
let req = Request {
|
let req = Request {
|
||||||
|
@ -27,6 +27,7 @@ ruma_api! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "client", feature = "server"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn response_content_type_override() {
|
fn response_content_type_override() {
|
||||||
let res = Response { stuff: "magic".into() };
|
let res = Response { stuff: "magic".into() };
|
||||||
@ -44,6 +45,7 @@ fn response_content_type_override() {
|
|||||||
assert_eq!(http_res.headers().get("content-type").unwrap(), "magic");
|
assert_eq!(http_res.headers().get("content-type").unwrap(), "magic");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "client")]
|
||||||
#[test]
|
#[test]
|
||||||
fn request_content_type_override() {
|
fn request_content_type_override() {
|
||||||
let req = Request { location: None, stuff: "magic".into() };
|
let req = Request { location: None, stuff: "magic".into() };
|
||||||
|
@ -16,6 +16,7 @@ ruma_api! {
|
|||||||
response: {}
|
response: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "client")]
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_request_http_repr() {
|
fn empty_request_http_repr() {
|
||||||
let req = Request {};
|
let req = Request {};
|
||||||
@ -24,6 +25,7 @@ fn empty_request_http_repr() {
|
|||||||
assert!(http_req.body().is_empty());
|
assert!(http_req.body().is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_response_http_repr() {
|
fn empty_response_http_repr() {
|
||||||
let res = Response {};
|
let res = Response {};
|
||||||
|
@ -22,6 +22,8 @@ serde_json = "1.0.61"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
unstable-exhaustive-types = []
|
unstable-exhaustive-types = []
|
||||||
|
client = []
|
||||||
|
server = []
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
matches = "0.1.8"
|
matches = "0.1.8"
|
||||||
|
@ -43,6 +43,7 @@ impl Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ruma_api::{exports::http, OutgoingRequest};
|
use ruma_api::{exports::http, OutgoingRequest};
|
||||||
|
@ -38,3 +38,5 @@ compat = []
|
|||||||
unstable-exhaustive-types = []
|
unstable-exhaustive-types = []
|
||||||
unstable-pre-spec = []
|
unstable-pre-spec = []
|
||||||
unstable-synapse-quirks = []
|
unstable-synapse-quirks = []
|
||||||
|
client = []
|
||||||
|
server = []
|
||||||
|
@ -75,6 +75,7 @@ struct ResponseBody {
|
|||||||
event_id: EventId,
|
event_id: EventId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl TryFrom<Response> for http::Response<Vec<u8>> {
|
impl TryFrom<Response> for http::Response<Vec<u8>> {
|
||||||
type Error = IntoHttpError;
|
type Error = IntoHttpError;
|
||||||
|
|
||||||
@ -88,6 +89,7 @@ impl TryFrom<Response> for http::Response<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "client")]
|
||||||
impl TryFrom<http::Response<Vec<u8>>> for Response {
|
impl TryFrom<http::Response<Vec<u8>>> for Response {
|
||||||
type Error = FromHttpResponseError<crate::Error>;
|
type Error = FromHttpResponseError<crate::Error>;
|
||||||
|
|
||||||
@ -109,6 +111,7 @@ impl TryFrom<http::Response<Vec<u8>>> for Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "client")]
|
||||||
impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
||||||
type EndpointError = crate::Error;
|
type EndpointError = crate::Error;
|
||||||
type IncomingResponse = Response;
|
type IncomingResponse = Response;
|
||||||
@ -152,6 +155,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl ruma_api::IncomingRequest for IncomingRequest {
|
impl ruma_api::IncomingRequest for IncomingRequest {
|
||||||
type EndpointError = crate::Error;
|
type EndpointError = crate::Error;
|
||||||
type OutgoingResponse = Response;
|
type OutgoingResponse = Response;
|
||||||
|
@ -68,6 +68,7 @@ struct ResponseBody {
|
|||||||
event_id: EventId,
|
event_id: EventId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl TryFrom<Response> for http::Response<Vec<u8>> {
|
impl TryFrom<Response> for http::Response<Vec<u8>> {
|
||||||
type Error = IntoHttpError;
|
type Error = IntoHttpError;
|
||||||
|
|
||||||
@ -81,6 +82,7 @@ impl TryFrom<Response> for http::Response<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "client")]
|
||||||
impl TryFrom<http::Response<Vec<u8>>> for Response {
|
impl TryFrom<http::Response<Vec<u8>>> for Response {
|
||||||
type Error = FromHttpResponseError<crate::Error>;
|
type Error = FromHttpResponseError<crate::Error>;
|
||||||
|
|
||||||
@ -102,6 +104,7 @@ impl TryFrom<http::Response<Vec<u8>>> for Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "client")]
|
||||||
impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
||||||
type EndpointError = crate::Error;
|
type EndpointError = crate::Error;
|
||||||
type IncomingResponse = Response;
|
type IncomingResponse = Response;
|
||||||
@ -144,6 +147,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl ruma_api::IncomingRequest for IncomingRequest {
|
impl ruma_api::IncomingRequest for IncomingRequest {
|
||||||
type EndpointError = crate::Error;
|
type EndpointError = crate::Error;
|
||||||
type OutgoingResponse = Response;
|
type OutgoingResponse = Response;
|
||||||
|
@ -71,6 +71,7 @@ struct ResponseBody {
|
|||||||
event_id: EventId,
|
event_id: EventId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl TryFrom<Response> for http::Response<Vec<u8>> {
|
impl TryFrom<Response> for http::Response<Vec<u8>> {
|
||||||
type Error = IntoHttpError;
|
type Error = IntoHttpError;
|
||||||
|
|
||||||
@ -84,6 +85,7 @@ impl TryFrom<Response> for http::Response<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "client")]
|
||||||
impl TryFrom<http::Response<Vec<u8>>> for Response {
|
impl TryFrom<http::Response<Vec<u8>>> for Response {
|
||||||
type Error = FromHttpResponseError<crate::Error>;
|
type Error = FromHttpResponseError<crate::Error>;
|
||||||
|
|
||||||
@ -105,6 +107,7 @@ impl TryFrom<http::Response<Vec<u8>>> for Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "client")]
|
||||||
impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
||||||
type EndpointError = crate::Error;
|
type EndpointError = crate::Error;
|
||||||
type IncomingResponse = Response;
|
type IncomingResponse = Response;
|
||||||
@ -148,6 +151,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "server")]
|
||||||
impl ruma_api::IncomingRequest for IncomingRequest {
|
impl ruma_api::IncomingRequest for IncomingRequest {
|
||||||
type EndpointError = crate::Error;
|
type EndpointError = crate::Error;
|
||||||
type OutgoingResponse = Response;
|
type OutgoingResponse = Response;
|
||||||
|
@ -30,3 +30,5 @@ matches = "0.1.8"
|
|||||||
[features]
|
[features]
|
||||||
unstable-exhaustive-types = []
|
unstable-exhaustive-types = []
|
||||||
unstable-pre-spec = []
|
unstable-pre-spec = []
|
||||||
|
client = []
|
||||||
|
server = []
|
||||||
|
@ -20,3 +20,5 @@ serde_json = "1.0.61"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
unstable-exhaustive-types = []
|
unstable-exhaustive-types = []
|
||||||
|
client = []
|
||||||
|
server = []
|
||||||
|
@ -22,3 +22,5 @@ serde_json = "1.0.61"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
unstable-exhaustive-types = []
|
unstable-exhaustive-types = []
|
||||||
|
client = []
|
||||||
|
server = []
|
||||||
|
@ -41,11 +41,25 @@ api = ["ruma-api"]
|
|||||||
events = ["ruma-events"]
|
events = ["ruma-events"]
|
||||||
signatures = ["ruma-signatures"]
|
signatures = ["ruma-signatures"]
|
||||||
|
|
||||||
appservice-api = ["api", "events", "ruma-appservice-api"]
|
appservice-api-c = ["api", "events", "ruma-appservice-api/client"]
|
||||||
client-api = ["api", "events", "ruma-client-api"]
|
appservice-api-s = ["api", "events", "ruma-appservice-api/server"]
|
||||||
federation-api = ["api", "signatures", "ruma-federation-api"]
|
appservice-api = ["appservice-api-c", "appservice-api-s"]
|
||||||
identity-service-api = ["api", "ruma-identity-service-api"]
|
|
||||||
push-gateway-api = ["api", "ruma-push-gateway-api"]
|
client-api-c = ["api", "events", "ruma-client-api/client"]
|
||||||
|
client-api-s = ["api", "events", "ruma-client-api/server"]
|
||||||
|
client-api = ["client-api-c", "client-api-s"]
|
||||||
|
|
||||||
|
federation-api-c = ["api", "signatures", "ruma-federation-api/client"]
|
||||||
|
federation-api-s = ["api", "signatures", "ruma-federation-api/server"]
|
||||||
|
federation-api = ["federation-api-c", "federation-api-s"]
|
||||||
|
|
||||||
|
identity-service-api-c = ["api", "ruma-identity-service-api/client"]
|
||||||
|
identity-service-api-s = ["api", "ruma-identity-service-api/server"]
|
||||||
|
identity-service-api = ["identity-service-api-c", "identity-service-api-s"]
|
||||||
|
|
||||||
|
push-gateway-api-c = ["api", "ruma-push-gateway-api/client"]
|
||||||
|
push-gateway-api-s = ["api", "ruma-push-gateway-api/server"]
|
||||||
|
push-gateway-api = ["push-gateway-api-c", "push-gateway-api-s"]
|
||||||
|
|
||||||
# Convenience features
|
# Convenience features
|
||||||
either = ["ruma-identifiers/either"]
|
either = ["ruma-identifiers/either"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user