pub trait Application:
Default
+ Sized
+ 'static {
type Cmd: Command + Configurable<Self::Cfg> + Parser;
type Cfg: Config;
type Paths: Default + ExePath + RootPath;
Show 15 methods
// Required methods
fn config(&self) -> Reader<Self::Cfg>;
fn state(&self) -> &State<Self>;
fn register_components(
&mut self,
command: &Self::Cmd,
) -> Result<(), FrameworkError>;
fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError>;
// Provided methods
fn run<I, T>(app_cell: &'static AppCell<Self>, args: I)
where I: IntoIterator<Item = T>,
T: Into<OsString> + Clone { ... }
fn init(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> { ... }
fn framework_components(
&mut self,
command: &Self::Cmd,
) -> Result<Vec<Box<dyn Component<Self>>>, FrameworkError> { ... }
fn load_config(&mut self, path: &Path) -> Result<Self::Cfg, FrameworkError> { ... }
fn name(&self) -> &'static str { ... }
fn description(&self) -> &'static str { ... }
fn authors(&self) -> Vec<String> { ... }
fn term_colors(&self, command: &Self::Cmd) -> ColorChoice { ... }
fn tracing_config(&self, command: &Self::Cmd) -> Config { ... }
fn shutdown(&self, shutdown: Shutdown) -> ! { ... }
fn shutdown_with_exitcode(&self, shutdown: Shutdown, exit_code: i32) -> ! { ... }
}
Expand description
Application types implementing this trait own global application state, including configuration and arbitrary other values stored within application components.
Application lifecycle is handled by a set of components owned by types implementing this trait. It also ties together the following:
Cmd
: application entrypointConfig
: application configurationPaths
: paths to various resources within the application
Required Associated Types§
Required Methods§
Sourcefn register_components(
&mut self,
command: &Self::Cmd,
) -> Result<(), FrameworkError>
fn register_components( &mut self, command: &Self::Cmd, ) -> Result<(), FrameworkError>
Register all components used by this application.
Sourcefn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError>
fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError>
Post-configuration lifecycle callback.
Called regardless of whether config is loaded to indicate this is the time in app lifecycle when configuration would be loaded if possible.
This method is responsible for invoking the after_config
handlers on
all components in the registry. This is presently done in the standard
application template, but is not otherwise handled directly by the
framework (as ownership precludes it).
Provided Methods§
Sourcefn run<I, T>(app_cell: &'static AppCell<Self>, args: I)
fn run<I, T>(app_cell: &'static AppCell<Self>, args: I)
Run application with the given command-line arguments and running the
appropriate Command
type.
Sourcefn init(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError>
fn init(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError>
Load this application’s configuration and initialize its components.
Sourcefn framework_components(
&mut self,
command: &Self::Cmd,
) -> Result<Vec<Box<dyn Component<Self>>>, FrameworkError>
fn framework_components( &mut self, command: &Self::Cmd, ) -> Result<Vec<Box<dyn Component<Self>>>, FrameworkError>
Initialize the framework’s default set of components, potentially sourcing terminal and tracing options from command line arguments.
Sourcefn load_config(&mut self, path: &Path) -> Result<Self::Cfg, FrameworkError>
fn load_config(&mut self, path: &Path) -> Result<Self::Cfg, FrameworkError>
Load configuration from the given path.
Returns an error if the configuration could not be loaded.
Sourcefn description(&self) -> &'static str
fn description(&self) -> &'static str
Description of this application.
Authors of this application.
Sourcefn term_colors(&self, command: &Self::Cmd) -> ColorChoice
fn term_colors(&self, command: &Self::Cmd) -> ColorChoice
Color configuration for this application.
Sourcefn tracing_config(&self, command: &Self::Cmd) -> Config
fn tracing_config(&self, command: &Self::Cmd) -> Config
Get the tracing configuration for this application.
Sourcefn shutdown(&self, shutdown: Shutdown) -> !
fn shutdown(&self, shutdown: Shutdown) -> !
Shut down this application gracefully, exiting with success.
Sourcefn shutdown_with_exitcode(&self, shutdown: Shutdown, exit_code: i32) -> !
fn shutdown_with_exitcode(&self, shutdown: Shutdown, exit_code: i32) -> !
Shut down this application gracefully, exiting with user-defined exit code.
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.