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§
Required Associated Types§
Required Methods§
Sourcefn run_with<T: AsyncScheduler + Send + 'static>(self, scheduler: T)
fn run_with<T: AsyncScheduler + Send + 'static>(self, scheduler: T)
Runs the application with an optional scheduler for async jobs.
Provided Methods§
Sourcefn register_with(self, server_tag: ServerTag, routes: Self::Routes) -> Selfwhere
Self: Sized,
fn register_with(self, server_tag: ServerTag, routes: Self::Routes) -> Selfwhere
Self: Sized,
Registers routes with a server tag.
Sourcefn register_debug(self, routes: Self::Routes) -> Selfwhere
Self: Sized,
fn register_debug(self, routes: Self::Routes) -> Selfwhere
Self: Sized,
Registers routes for debugger.
Sourcefn add_plugin(self, plugin: Plugin) -> Selfwhere
Self: Sized,
fn add_plugin(self, plugin: Plugin) -> Selfwhere
Self: Sized,
Adds a custom plugin.
Returns a reference to the shared application state.
Sourcefn state_data() -> &'static Map
fn state_data() -> &'static Map
Returns a reference to the shared application state data.
Sourcefn secret_key() -> &'static [u8] ⓘ
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.
Sourcefn project_dir() -> &'static PathBuf
fn project_dir() -> &'static PathBuf
Returns the project directory for the application.
Sourcefn config_dir() -> &'static PathBuf
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
.
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
Sourcefn parse_path(path: &str) -> PathBuf
fn parse_path(path: &str) -> PathBuf
Parses an absolute path, or a path relative to the home dir ~/
or project dir.
Sourceasync fn fetch(url: &str, options: Option<&Map>) -> Result<Response, Error>
Available on crate feature http-client
only.
async fn fetch(url: &str, options: Option<&Map>) -> Result<Response, Error>
http-client
only.Makes an HTTP request to the provided URL.
Sourceasync fn fetch_json<T: DeserializeOwned>(
url: &str,
options: Option<&Map>,
) -> Result<T, Error>
Available on crate feature http-client
only.
async fn fetch_json<T: DeserializeOwned>( url: &str, options: Option<&Map>, ) -> Result<T, Error>
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.