Skip to main content

ModuleBuilderMountExt

Trait ModuleBuilderMountExt 

Source
pub trait ModuleBuilderMountExt {
    // Required method
    fn mount(&mut self, mount: Mount) -> &mut Self;
}
Expand description

Mounting tower services on a ModuleBuilder.

use std::convert::Infallible;

use http::Method;
use navree_http::body::Body;
use navree_http::extract::Request;
use navree_http::{ModuleBuilderMountExt, Mount};
use navree_kernel::{Module, ModuleBuilder};

struct BalanceModule;

impl Module for BalanceModule {
    fn register(&self, m: &mut ModuleBuilder) {
        // A service of another crate, written with tower alone.
        let balance = tower::service_fn(|_request: Request| async {
            Ok::<_, Infallible>(http::Response::new(Body::from("₹1,00,000")))
        });
        m.mount(
            Mount::new("/balance", balance)
                .public()
                .methods(&[Method::GET]),
        );
    }
}

Required Methods§

Source

fn mount(&mut self, mount: Mount) -> &mut Self

Serves mount’s service under its prefix. The boot checks the mount with the app’s routes and other mounts (see Mount).

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 ModuleBuilderMountExt for ModuleBuilder

Source§

fn mount(&mut self, mount: Mount) -> &mut Self

Implementors§