pub struct Config { /* private fields */ }Expand description
The application’s configuration tree.
Cloning is cheap: every clone shares one store, so a handler can hold a
Config without copying the tree.
Implementations§
Source§impl Config
impl Config
pub fn new() -> Self
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Seed the tree with the framework’s defaults, honouring .env.
Sourcepub fn load_dir(&self, dir: impl AsRef<Path>) -> Result<()>
pub fn load_dir(&self, dir: impl AsRef<Path>) -> Result<()>
Load every config/*.json file, keyed by file stem.
config/app.json becomes the app.* namespace, mirroring Laravel’s
config/app.php. String values support ${VAR} interpolation so a
config file can defer to .env.
Sourcepub fn set(&self, path: &str, value: impl Into<Json>)
pub fn set(&self, path: &str, value: impl Into<Json>)
Set (or replace) a value at a dotted path.
Sourcepub fn merge(&self, namespace: &str, value: Json)
pub fn merge(&self, namespace: &str, value: Json)
Merge an object into a namespace, keeping keys that are not overridden.
pub fn string(&self, path: &str, default: &str) -> String
pub fn int(&self, path: &str, default: i64) -> i64
Sourcepub fn list(&self, path: &str) -> Vec<String>
pub fn list(&self, path: &str) -> Vec<String>
A list, from either a JSON array or one comma-separated string.
The string form exists because of .env: a variable can only hold a
string, so CORS_ALLOWED_ORIGINS=https://a.example,https://b.example
has to mean the same as the array it would be in JSON. Items are
trimmed and empty ones dropped, so a trailing comma is not an entry.
pub fn bool(&self, path: &str, default: bool) -> bool
Sourcepub fn environment(&self) -> String
pub fn environment(&self) -> String
The current environment name: local, production, testing.