[][src]Trait replicante_util_actixweb::RootDescriptor

pub trait RootDescriptor {
    fn enabled(&self, flags: &APIFlags) -> bool;
fn prefix(&self) -> &'static str; fn and_then<C>(&self, flags: &APIFlags, config: C)
    where
        C: FnOnce(&Self)
, { ... }
fn resource(&self, path: &str) -> Resource { ... } }

Interface for types that describe endpoint roots.

Useful to codify in a sensible way which possible paths are exposed by an API.

Example

use replicante_util_actixweb::RootDescriptor;

enum APIVersion {
    V1,
    V2,
    V3,
}

impl RootDescriptor for APIVersion {
    fn enabled(&self, flags: &HashMap<&'static str, bool>) -> bool {
        match self {
            APIVersion::V1 => match flags.get("v1") {
                Some(flag) => *flag,
                None => match flags.get("legacy") {
                    Some(flag) => *flag,
                    None => true,
                },
            },
            APIVersion::V2 => match flags.get("v2") {
                Some(flag) => *flag,
                None => match flags.get("legacy") {
                    Some(flag) => *flag,
                    None => true,
                },
            },
            APIVersion::V3 => true,
        }
    }

    fn prefix(&self) -> &'static str {
        match self {
            APIVersion::V1 => "/api/v1",
            APIVersion::V2 => "/some/other/path",
            APIVersion::V3 => "/v3",
        }
    }
}

Required methods

fn enabled(&self, flags: &APIFlags) -> bool

Check if a root should be enabled according to the given flags.

fn prefix(&self) -> &'static str

Return the URI prefix for a root.

Loading content...

Provided methods

fn and_then<C>(&self, flags: &APIFlags, config: C) where
    C: FnOnce(&Self), 

Perform configuration only if the root is enabled.

fn resource(&self, path: &str) -> Resource

👎 Deprecated since 0.2.0:

use AppConfig and AppConfigContext::scoped_service

Create a resource for a path underneath the root.

Loading content...

Implementors

Loading content...