Expand description
Process events, external directories and metadata.
This module contains functions and macros that operate on the executable level, not the app level. Zng apps can have multiple process instances, most common a view-process and app-process pair, plus the crash handler.
The app-process is the normal execution, the other processes use on_process_start! to takeover the
process if specific environment variables are set. The process start handlers are called on init!,
if a process takeover it exits without returning, so only the normal app-process code executes after init!().
fn main() {
println!("print in all processes");
zng::env::init!();
println!("print only in the app-process");
// get a path in the app config dir, the config dir is created if needed.
let my_config = zng::env::config("my-config.txt");
// read a config file, or create it
if let Ok(c) = std::fs::read_to_string(&my_config) {
println!("{c}");
} else {
std::fs::write(zng::env::config("my-config.txt"), b"Hello!").unwrap();
}
}Note that init must be called in main, it must be called in main to define the lifetime of the processes,
this is needed to properly call on_process_exit handlers.
Also see init! docs for details init in "wasm32" and "android" target builds.
§Full API
See zng_env for the full API.
Macros§
- init
- Inits process metadata, calls process start handlers and defines the process lifetime in
main. - on_
process_ start - Register a
FnOnce(&ProcessStartArgs)closure to be called oninit!.
Structs§
- About
- Metadata about the app and main crate.
- Process
Exit Args - Arguments for
on_process_exithandlers. - Process
Start Args - Arguments for
on_process_starthandlers.
Functions§
- about
- Gets metadata about the application.
- bin
- Gets a path relative to the package binaries.
- cache
- Gets a path relative to the cache directory for the app.
- clear_
cache - Removes all cache files possible.
- config
- Gets a path relative to the user config directory for the app.
- exit
- Terminates the current process with the specified exit code.
- init_
built_ res - Sets a custom path for the “built resources” override checked by
resin debug builds. - init_
cache - Sets a custom
cachepath. - init_
config - Sets a custom
original_configpath. - init_
res - Sets a custom
respath. - migrate_
cache - Save
new_pathas the new cache path and make a best effort to move existing cache files. - migrate_
config - Copies all config to
new_pathand saves it as the config path. - on_
process_ exit - Register a
handlerto run once when the current process exits. - process_
name - Gets a process runtime name.
- res
- Gets a path relative to the package resources.