Skip to main content

AddRouterExt

Trait AddRouterExt 

Source
pub trait AddRouterExt {
    // Required methods
    fn add_router<T>(&self, router: impl Into<Arc<T>>)
       where T: RouterBuilder + 'static;
    fn has_router<T>(&self) -> bool
       where T: RouterBuilder + 'static;
}
Expand description

Registers concrete RouterBuilder instances on the public HTTP server.

This extension lives on AppContext, so routers can be registered both while configuring the AppBuilder and from within a plugin’s build. A router is identified by its type: at most one instance of a given type may be registered.

Registration does not require HttpServerPlugin; if the plugin is never added the router is simply never served.

Required Methods§

Source

fn add_router<T>(&self, router: impl Into<Arc<T>>)
where T: RouterBuilder + 'static,

Registers router on the public HTTP server.

The router is stored under its concrete type T. To expose several distinct sets of routes use distinct types; a single type that needs many routes should build them all in its RouterBuilder implementation.

§Panics

Panics if a router of type T is already registered on this server. Guard with has_router when the same type may be registered more than once (for example from several bundles).

Source

fn has_router<T>(&self) -> bool
where T: RouterBuilder + 'static,

Returns whether a router of type T is registered on the public server.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl AddRouterExt for AppContext

Source§

fn add_router<T>(&self, router: impl Into<Arc<T>>)
where T: RouterBuilder + 'static,

Source§

fn has_router<T>(&self) -> bool
where T: RouterBuilder + 'static,

Implementors§