Trait Application

Source
pub trait Application {
    type Routes;

    const APP_TYPE: AppType;
Show 25 methods // Required methods fn register(self, routes: Self::Routes) -> Self; fn run_with<T: AsyncScheduler + Send + 'static>(self, scheduler: T); // Provided methods fn boot() -> Self where Self: Default { ... } fn boot_with<F>(init: F) -> Self where Self: Default, F: FnOnce(&'static State<Map>) { ... } fn register_with(self, server_tag: ServerTag, routes: Self::Routes) -> Self where Self: Sized { ... } fn register_debug(self, routes: Self::Routes) -> Self where Self: Sized { ... } fn add_plugin(self, plugin: Plugin) -> Self where Self: Sized { ... } fn shared_state() -> &'static State<Map> { ... } fn env() -> &'static Env { ... } fn config() -> &'static Table { ... } fn state_data() -> &'static Map { ... } fn name() -> &'static str { ... } fn version() -> &'static str { ... } fn domain() -> &'static str { ... } fn secret_key() -> &'static [u8] { ... } fn project_dir() -> &'static PathBuf { ... } fn config_dir() -> &'static PathBuf { ... } fn shared_dir(name: &str) -> Cow<'_, PathBuf> { ... } fn parse_path(path: &str) -> PathBuf { ... } fn spawn<T>(self, scheduler: T) -> Self where Self: Sized, T: Scheduler + Send + 'static { ... } fn run(self) where Self: Sized { ... } async fn load() { ... } async fn shutdown() { ... } async fn fetch(url: &str, options: Option<&Map>) -> Result<Response, Error> { ... } async fn fetch_json<T: DeserializeOwned>( url: &str, options: Option<&Map>, ) -> Result<T, Error> { ... }
}
Expand description

Application interfaces.

Required Associated Constants§

Source

const APP_TYPE: AppType

Application type.

Required Associated Types§

Source

type Routes

Routes.

Required Methods§

Source

fn register(self, routes: Self::Routes) -> Self

Registers default routes.

Source

fn run_with<T: AsyncScheduler + Send + 'static>(self, scheduler: T)

Runs the application with an optional scheduler for async jobs.

Provided Methods§

Source

fn boot() -> Self
where Self: Default,

Boots the application with the default initialization.

Source

fn boot_with<F>(init: F) -> Self
where Self: Default, F: FnOnce(&'static State<Map>),

Boots the application with a custom initialization.

Source

fn register_with(self, server_tag: ServerTag, routes: Self::Routes) -> Self
where Self: Sized,

Registers routes with a server tag.

Source

fn register_debug(self, routes: Self::Routes) -> Self
where Self: Sized,

Registers routes for debugger.

Source

fn add_plugin(self, plugin: Plugin) -> Self
where Self: Sized,

Adds a custom plugin.

Source

fn shared_state() -> &'static State<Map>

Returns a reference to the shared application state.

Source

fn env() -> &'static Env

Returns the application env.

Source

fn config() -> &'static Table

Returns a reference to the shared application config.

Source

fn state_data() -> &'static Map

Returns a reference to the shared application state data.

Source

fn name() -> &'static str

Returns the application name.

Source

fn version() -> &'static str

Returns the application version.

Source

fn domain() -> &'static str

Returns the domain for the application.

Source

fn secret_key() -> &'static [u8]

Returns the secret key for the application. It should have at least 64 bytes.

§Note

This should only be used for internal services. Do not expose it to external users.

Source

fn project_dir() -> &'static PathBuf

Returns the project directory for the application.

Source

fn config_dir() -> &'static PathBuf

Returns the config directory for the application.

§Note

The default config directory is ${PROJECT_DIR}/config. It can also be specified by the environment variable ZINO_APP_CONFIG_DIR.

Source

fn shared_dir(name: &str) -> Cow<'_, PathBuf>

Returns the shared directory with a specific name, which is defined in the dirs table.

§Examples
[dirs]
data = "/data/zino" # an absolute path
cache = "~/zino/cache" # a path in the home dir
assets = "local/assets" # a path in the project dir
Source

fn parse_path(path: &str) -> PathBuf

Parses an absolute path, or a path relative to the home dir ~/ or project dir.

Source

fn spawn<T>(self, scheduler: T) -> Self
where Self: Sized, T: Scheduler + Send + 'static,

Spawns a new thread to run cron jobs.

Source

fn run(self)
where Self: Sized,

Runs the application with a default job scheduler.

Source

async fn load()

Loads resources after booting the application.

Source

async fn shutdown()

Handles the graceful shutdown.

Source

async fn fetch(url: &str, options: Option<&Map>) -> Result<Response, Error>

Available on crate feature http-client only.

Makes an HTTP request to the provided URL.

Source

async fn fetch_json<T: DeserializeOwned>( url: &str, options: Option<&Map>, ) -> Result<T, Error>

Available on crate feature http-client only.

Makes an HTTP request to the provided URL and deserializes the response body via JSON.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Application for Agent

Source§

const APP_TYPE: AppType = AppType::Agent

Source§

type Routes = ()