pub struct Config {
pub defaults: DefaultsConfig,
pub paths: PathsConfig,
}
Expand description
Global configuration for the blz cache system.
Contains default settings that apply to all sources unless overridden by per-source configuration. Configuration is automatically loaded from the system config directory or created with sensible defaults.
§File Location
The configuration file is stored at (searched in order):
- XDG:
$XDG_CONFIG_HOME/blz/config.toml
or~/.config/blz/config.toml
- Dotfile fallback:
~/.blz/config.toml
A config.local.toml
in the same directory overrides keys from config.toml
.
§Example Configuration File
[defaults]
refresh_hours = 24
max_archives = 10
fetch_enabled = true
follow_links = "first_party"
allowlist = ["docs.rs", "developer.mozilla.org"]
[paths]
root = "/home/user/.outfitter/blz"
Fields§
§defaults: DefaultsConfig
Default settings for all sources
paths: PathsConfig
File system paths configuration
Implementations§
Source§impl Config
impl Config
Sourcepub fn load() -> Result<Self>
pub fn load() -> Result<Self>
Load configuration from the default location or create with defaults.
This method attempts to load the configuration from the system config directory. If the file doesn’t exist, it returns a configuration with sensible defaults. If the file exists but is malformed, it returns an error.
§Returns
Returns the loaded configuration or a default configuration if no file exists.
§Errors
Returns an error if:
- The config directory cannot be determined (unsupported platform)
- The config file exists but cannot be read (permissions, I/O error)
- The config file exists but contains invalid TOML syntax
- The config file exists but contains invalid configuration values
§Examples
use blz_core::Config;
// Load existing config or create with defaults
let config = Config::load()?;
if config.defaults.fetch_enabled {
println!("Fetching is enabled");
}
Sourcepub fn save(&self) -> Result<()>
pub fn save(&self) -> Result<()>
Save the configuration to the default location.
This method serializes the configuration to TOML format and writes it to the system config directory. Parent directories are created if they don’t exist.
§Errors
Returns an error if:
- The config directory cannot be determined (unsupported platform)
- Parent directories cannot be created (permissions, disk space)
- The configuration cannot be serialized to TOML
- The file cannot be written (permissions, disk space, I/O error)
§Examples
use blz_core::{Config, DefaultsConfig, PathsConfig, FollowLinks};
use std::path::PathBuf;
let mut config = Config::load()?;
config.defaults.refresh_hours = 12; // Update refresh interval
config.save()?; // Persist changes
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more