Macro k8s_openapi::k8s_match[][src]

macro_rules! k8s_match {
    (@inner { $test:expr } { $($arms:tt)* } { }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_1_7!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_ge_1_7!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_le_1_7!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_1_8!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_ge_1_8!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_le_1_8!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_1_9!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_ge_1_9!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_le_1_9!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_1_10!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_ge_1_10!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_le_1_10!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_1_11!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_ge_1_11!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { k8s_if_le_1_11!($($arm:tt)*), $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { $next_pat:pat => $next_expr:expr, $($rest:tt)* }) => { ... };
    (@inner { $test:expr } { $($arms:tt)* } { $next_pat:pat if $cond:expr => $next_expr:expr, $($rest:tt)* }) => { ... };
    ($test:expr, { $($rest:tt)* }) => { ... };
}

A macro that emits a match expr with the given test expression and arms. The match arms can be annotated with the other conditional compilation macros in this crate so that they're only emitted if the predicate is true.

Examples

The CustomResourceDefinition::create_apiextensions_v1beta1_custom_resource_definition function returns an HTTP 201 CREATED when it succeeds, but the codegen before v1.9 does not have a Created variant in the response type. So extracting the successful result from the response requires matching CreateApiextensionsV1beta1CustomResourceDefinitionResponse::Other for v1.8 and below and CreateApiextensionsV1beta1CustomResourceDefinitionResponse::Created for v1.9 and above.

Since CreateApiextensionsV1beta1CustomResourceDefinitionResponse::Created does not exist in v1.8 and below, and CreateApiextensionsV1beta1CustomResourceDefinitionResponse::Other would not be returned in v1.9 and above, both arms need to be wrapped in conditional compilation predicates.

This example is not tested
let custom_resource_definition = k8s_match!(response, {
    k8s_if_le_1_8!(CreateApiextensionsV1beta1CustomResourceDefinitionResponse::Other if status_code == ::http::StatusCode::CREATED => {
        // Parse response body into a CustomResourceDefinition
        Ok(unimplemented!())
    }),
    k8s_if_ge_1_9!(CreateApiextensionsV1beta1CustomResourceDefinitionResponse::Created(custom_resource_definition) => {
        Ok(custom_resource_definition)
    }),
    other => Err(format!("unexpected response {} {:?}", status_code, other)),
})?;