diff --git a/ruma-api-macros/src/api.rs b/ruma-api-macros/src/api.rs index 69fc1d51..b05e8476 100644 --- a/ruma-api-macros/src/api.rs +++ b/ruma-api-macros/src/api.rs @@ -267,12 +267,14 @@ pub fn expand_all(api: Api) -> syn::Result { quote! { #( #attrs )* #[automatically_derived] + #[cfg(feature = "client")] impl #request_lifetimes #ruma_api::OutgoingNonAuthRequest for Request #request_lifetimes {} #( #attrs )* #[automatically_derived] + #[cfg(feature = "server")] impl #ruma_api::IncomingNonAuthRequest for #incoming_request_type {} } } @@ -287,6 +289,7 @@ pub fn expand_all(api: Api) -> syn::Result { #response_type #[automatically_derived] + #[cfg(feature = "server")] impl ::std::convert::TryFrom for #http::Response> { type Error = #ruma_api::error::IntoHttpError; @@ -308,6 +311,7 @@ pub fn expand_all(api: Api) -> syn::Result { } #[automatically_derived] + #[cfg(feature = "client")] impl ::std::convert::TryFrom<#http::Response>> for Response { type Error = #ruma_api::error::FromHttpResponseError<#error>; @@ -344,6 +348,7 @@ pub fn expand_all(api: Api) -> syn::Result { }; #[automatically_derived] + #[cfg(feature = "client")] impl #request_lifetimes #ruma_api::OutgoingRequest for Request #request_lifetimes { type EndpointError = #error; type IncomingResponse = ::Incoming; @@ -386,6 +391,7 @@ pub fn expand_all(api: Api) -> syn::Result { } #[automatically_derived] + #[cfg(feature = "server")] impl #ruma_api::IncomingRequest for #incoming_request_type { type EndpointError = #error; type OutgoingResponse = Response; diff --git a/ruma-api/Cargo.toml b/ruma-api/Cargo.toml index 6912a215..11087bee 100644 --- a/ruma-api/Cargo.toml +++ b/ruma-api/Cargo.toml @@ -31,3 +31,9 @@ thiserror = "1.0.23" [dev-dependencies] ruma-events = { version = "=0.22.0-alpha.2", path = "../ruma-events" } 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 = [] diff --git a/ruma-api/tests/conversions.rs b/ruma-api/tests/conversions.rs index 69e6307f..da4ae27b 100644 --- a/ruma-api/tests/conversions.rs +++ b/ruma-api/tests/conversions.rs @@ -34,6 +34,7 @@ ruma_api! { } } +#[cfg(all(feature = "client", feature = "server"))] #[test] fn request_serde() -> Result<(), Box> { let req = Request { diff --git a/ruma-api/tests/header_override.rs b/ruma-api/tests/header_override.rs index b96b8a07..d55b4efa 100644 --- a/ruma-api/tests/header_override.rs +++ b/ruma-api/tests/header_override.rs @@ -27,6 +27,7 @@ ruma_api! { } } +#[cfg(all(feature = "client", feature = "server"))] #[test] fn response_content_type_override() { 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"); } +#[cfg(feature = "client")] #[test] fn request_content_type_override() { let req = Request { location: None, stuff: "magic".into() }; diff --git a/ruma-api/tests/no_fields.rs b/ruma-api/tests/no_fields.rs index f09a85bb..fd9b831c 100644 --- a/ruma-api/tests/no_fields.rs +++ b/ruma-api/tests/no_fields.rs @@ -16,6 +16,7 @@ ruma_api! { response: {} } +#[cfg(feature = "client")] #[test] fn empty_request_http_repr() { let req = Request {}; @@ -24,6 +25,7 @@ fn empty_request_http_repr() { assert!(http_req.body().is_empty()); } +#[cfg(feature = "server")] #[test] fn empty_response_http_repr() { let res = Response {}; diff --git a/ruma-appservice-api/Cargo.toml b/ruma-appservice-api/Cargo.toml index a3141a9d..405a0358 100644 --- a/ruma-appservice-api/Cargo.toml +++ b/ruma-appservice-api/Cargo.toml @@ -22,6 +22,8 @@ serde_json = "1.0.61" [features] unstable-exhaustive-types = [] +client = [] +server = [] [dev-dependencies] matches = "0.1.8" diff --git a/ruma-appservice-api/src/event/push_events/v1.rs b/ruma-appservice-api/src/event/push_events/v1.rs index d16e52ff..f0a584c3 100644 --- a/ruma-appservice-api/src/event/push_events/v1.rs +++ b/ruma-appservice-api/src/event/push_events/v1.rs @@ -43,6 +43,7 @@ impl Response { } } +#[cfg(feature = "server")] #[cfg(test)] mod tests { use ruma_api::{exports::http, OutgoingRequest}; diff --git a/ruma-client-api/Cargo.toml b/ruma-client-api/Cargo.toml index e08c005c..89f27f5f 100644 --- a/ruma-client-api/Cargo.toml +++ b/ruma-client-api/Cargo.toml @@ -38,3 +38,5 @@ compat = [] unstable-exhaustive-types = [] unstable-pre-spec = [] unstable-synapse-quirks = [] +client = [] +server = [] diff --git a/ruma-client-api/src/r0/message/send_message_event.rs b/ruma-client-api/src/r0/message/send_message_event.rs index 5f14e98a..b443261d 100644 --- a/ruma-client-api/src/r0/message/send_message_event.rs +++ b/ruma-client-api/src/r0/message/send_message_event.rs @@ -75,6 +75,7 @@ struct ResponseBody { event_id: EventId, } +#[cfg(feature = "server")] impl TryFrom for http::Response> { type Error = IntoHttpError; @@ -88,6 +89,7 @@ impl TryFrom for http::Response> { } } +#[cfg(feature = "client")] impl TryFrom>> for Response { type Error = FromHttpResponseError; @@ -109,6 +111,7 @@ impl TryFrom>> for Response { } } +#[cfg(feature = "client")] impl<'a> ruma_api::OutgoingRequest for Request<'a> { type EndpointError = crate::Error; type IncomingResponse = Response; @@ -152,6 +155,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> { } } +#[cfg(feature = "server")] impl ruma_api::IncomingRequest for IncomingRequest { type EndpointError = crate::Error; type OutgoingResponse = Response; diff --git a/ruma-client-api/src/r0/state/send_state_event_for_empty_key.rs b/ruma-client-api/src/r0/state/send_state_event_for_empty_key.rs index c2532be8..bc5c9dfb 100644 --- a/ruma-client-api/src/r0/state/send_state_event_for_empty_key.rs +++ b/ruma-client-api/src/r0/state/send_state_event_for_empty_key.rs @@ -68,6 +68,7 @@ struct ResponseBody { event_id: EventId, } +#[cfg(feature = "server")] impl TryFrom for http::Response> { type Error = IntoHttpError; @@ -81,6 +82,7 @@ impl TryFrom for http::Response> { } } +#[cfg(feature = "client")] impl TryFrom>> for Response { type Error = FromHttpResponseError; @@ -102,6 +104,7 @@ impl TryFrom>> for Response { } } +#[cfg(feature = "client")] impl<'a> ruma_api::OutgoingRequest for Request<'a> { type EndpointError = crate::Error; type IncomingResponse = Response; @@ -144,6 +147,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> { } } +#[cfg(feature = "server")] impl ruma_api::IncomingRequest for IncomingRequest { type EndpointError = crate::Error; type OutgoingResponse = Response; diff --git a/ruma-client-api/src/r0/state/send_state_event_for_key.rs b/ruma-client-api/src/r0/state/send_state_event_for_key.rs index a374f3d9..a5eb6142 100644 --- a/ruma-client-api/src/r0/state/send_state_event_for_key.rs +++ b/ruma-client-api/src/r0/state/send_state_event_for_key.rs @@ -71,6 +71,7 @@ struct ResponseBody { event_id: EventId, } +#[cfg(feature = "server")] impl TryFrom for http::Response> { type Error = IntoHttpError; @@ -84,6 +85,7 @@ impl TryFrom for http::Response> { } } +#[cfg(feature = "client")] impl TryFrom>> for Response { type Error = FromHttpResponseError; @@ -105,6 +107,7 @@ impl TryFrom>> for Response { } } +#[cfg(feature = "client")] impl<'a> ruma_api::OutgoingRequest for Request<'a> { type EndpointError = crate::Error; type IncomingResponse = Response; @@ -148,6 +151,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> { } } +#[cfg(feature = "server")] impl ruma_api::IncomingRequest for IncomingRequest { type EndpointError = crate::Error; type OutgoingResponse = Response; diff --git a/ruma-federation-api/Cargo.toml b/ruma-federation-api/Cargo.toml index 5f033aee..e09a4474 100644 --- a/ruma-federation-api/Cargo.toml +++ b/ruma-federation-api/Cargo.toml @@ -30,3 +30,5 @@ matches = "0.1.8" [features] unstable-exhaustive-types = [] unstable-pre-spec = [] +client = [] +server = [] diff --git a/ruma-identity-service-api/Cargo.toml b/ruma-identity-service-api/Cargo.toml index 8f3d902a..ad252b5a 100644 --- a/ruma-identity-service-api/Cargo.toml +++ b/ruma-identity-service-api/Cargo.toml @@ -20,3 +20,5 @@ serde_json = "1.0.61" [features] unstable-exhaustive-types = [] +client = [] +server = [] diff --git a/ruma-push-gateway-api/Cargo.toml b/ruma-push-gateway-api/Cargo.toml index a39a35e8..04583584 100644 --- a/ruma-push-gateway-api/Cargo.toml +++ b/ruma-push-gateway-api/Cargo.toml @@ -22,3 +22,5 @@ serde_json = "1.0.61" [features] unstable-exhaustive-types = [] +client = [] +server = [] diff --git a/ruma/Cargo.toml b/ruma/Cargo.toml index 7fd40d1f..094e949d 100644 --- a/ruma/Cargo.toml +++ b/ruma/Cargo.toml @@ -41,11 +41,25 @@ api = ["ruma-api"] events = ["ruma-events"] signatures = ["ruma-signatures"] -appservice-api = ["api", "events", "ruma-appservice-api"] -client-api = ["api", "events", "ruma-client-api"] -federation-api = ["api", "signatures", "ruma-federation-api"] -identity-service-api = ["api", "ruma-identity-service-api"] -push-gateway-api = ["api", "ruma-push-gateway-api"] +appservice-api-c = ["api", "events", "ruma-appservice-api/client"] +appservice-api-s = ["api", "events", "ruma-appservice-api/server"] +appservice-api = ["appservice-api-c", "appservice-api-s"] + +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 either = ["ruma-identifiers/either"]