zng/
env.rs

1//! Process events, external directories and metadata.
2//!
3//! This module contains functions and macros that operate on the executable level, not the app level. Zng apps
4//! can have multiple process instances, most common a view-process and app-process pair, plus the crash handler.
5//!
6//! The app-process is the normal execution, the other processes use [`on_process_start!`] to takeover the
7//! process if specific environment variables are set. The process start handlers are called on [`init!`],
8//! if a process takeover it exits without returning, so only the normal app-process code executes after `init!()`.
9//!
10//! ```no_run
11//! fn main() {
12//!    println!("print in all processes");
13//!    zng::env::init!();
14//!    println!("print only in the app-process");
15//!
16//!    // get a path in the app config dir, the config dir is created if needed.    
17//!    let my_config = zng::env::config("my-config.txt");
18//!
19//!    // read a config file, or create it
20//!    if let Ok(c) = std::fs::read_to_string(&my_config) {
21//!       println!("{c}");
22//!    } else {
23//!       std::fs::write(zng::env::config("my-config.txt"), b"Hello!").unwrap();
24//!    }
25//! }
26//! ```
27//!
28//! Note that init **must be called in main**, it must be called in main to define the lifetime of the processes,
29//! this is needed to properly call [`on_process_exit`] handlers.
30//!
31//! Also see [`init!`] docs for details init in `"wasm32"` and `"android"` target builds.
32//!
33//! # Full API
34//!
35//! See [`zng_env`] for the full API.
36
37pub use zng_env::{
38    About, ProcessExitArgs, ProcessStartArgs, about, bin, cache, clear_cache, config, exit, init, init_cache, init_config, init_res,
39    migrate_cache, migrate_config, on_process_exit, on_process_start, res,
40};
41
42#[cfg(target_os = "android")]
43pub use zng_env::{android_external, android_install_res};
44
45#[cfg(any(debug_assertions, feature = "built_res"))]
46pub use zng_env::init_built_res;