pub struct ConfigManager { /* private fields */ }Expand description
Unified runtime configuration manager for aria2-rust.
ConfigManager provides a two-tier option storage system:
- Global options: Shared across all download tasks
- Task-level options: Per-task overrides that inherit from globals
Options are loaded from four sources in priority order:
- Built-in defaults (from
OptionRegistry) - Environment variables (
ARIA2_*prefix) - Configuration file (
~/.aria2/aria2.conf) - Command-line arguments (highest priority)
§Example
use aria2_core::config::ConfigManager;
use aria2_core::config::OptionValue;
#[tokio::main]
async fn main() {
let mut mgr = ConfigManager::new();
mgr.set_global_option("split", OptionValue::Int(8)).await.unwrap();
assert_eq!(mgr.get_global_i64("split").await, Some(8));
}Implementations§
Source§impl ConfigManager
impl ConfigManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ConfigManager with the built-in OptionRegistry
containing ~95 core aria2 options.
Sourcepub fn new_with_registry(registry: OptionRegistry) -> Self
pub fn new_with_registry(registry: OptionRegistry) -> Self
Create a ConfigManager with a custom OptionRegistry.
Use this when you need to register custom options beyond the built-in set (e.g., application-specific configuration).
Sourcepub async fn load_cli(&mut self, args: &[String])
pub async fn load_cli(&mut self, args: &[String])
Parse and load command-line arguments into global options.
Supports formats: --opt=val, --opt val, -o val, --no-opt,
and @file for URI list file references.
Sourcepub async fn load_file(&mut self, path: &str)
pub async fn load_file(&mut self, path: &str)
Load options from an aria2.conf-format configuration file.
Sourcepub async fn load_env(&mut self)
pub async fn load_env(&mut self)
Load options from environment variables with ARIA2_ prefix.
Maps ARIA2_SPLIT → split, ARIA2_DIR → dir, etc.
Sourcepub async fn get_global_option(&self, name: &str) -> Option<OptionValue>
pub async fn get_global_option(&self, name: &str) -> Option<OptionValue>
Get a global option value by name.
Sourcepub async fn get_global_str(&self, name: &str) -> Option<String>
pub async fn get_global_str(&self, name: &str) -> Option<String>
Convenience: get a global option as a String.
Returns None if the option doesn’t exist or is not a string type.
Sourcepub async fn get_global_i64(&self, name: &str) -> Option<i64>
pub async fn get_global_i64(&self, name: &str) -> Option<i64>
Convenience: get a global option as an i64 integer.
Returns None if the option doesn’t exist or is not an integer type.
Sourcepub async fn get_global_bool(&self, name: &str) -> Option<bool>
pub async fn get_global_bool(&self, name: &str) -> Option<bool>
Convenience: get a global option as a bool.
Returns None if the option doesn’t exist or is not a boolean type.
Sourcepub async fn set_global_option(
&mut self,
name: &str,
value: OptionValue,
) -> Result<(), String>
pub async fn set_global_option( &mut self, name: &str, value: OptionValue, ) -> Result<(), String>
Set a global option value with validation.
Validates against the OptionRegistry (type checking, range validation).
Emits a ConfigChangeEvent on success. Returns an error for unknown
options or validation failures.
Sourcepub async fn change_global_options(
&mut self,
options: HashMap<String, String>,
) -> Vec<String>
pub async fn change_global_options( &mut self, options: HashMap<String, String>, ) -> Vec<String>
Batch-set multiple global options (RPC changeGlobalOption compatible).
Returns a list of error messages for each failed option. Options that succeed are applied immediately.
pub async fn get_all_global_options(&self) -> HashMap<String, OptionValue>
pub async fn get_all_global_options_json(&self) -> Value
pub async fn get_task_default( &self, gid: &str, name: &str, ) -> Option<OptionValue>
pub async fn set_task_option( &mut self, gid: &str, name: &str, value: OptionValue, ) -> Result<(), String>
pub async fn change_task_options( &mut self, gid: &str, options: HashMap<String, String>, ) -> Vec<String>
pub async fn get_task_options(&self, gid: &str) -> HashMap<String, OptionValue>
pub async fn remove_task(&mut self, gid: &str)
Sourcepub fn subscribe_changes(&self) -> Receiver<ConfigChangeEvent>
pub fn subscribe_changes(&self) -> Receiver<ConfigChangeEvent>
Subscribe to configuration change events.
Returns a broadcast::Receiver that receives ConfigChangeEvent
whenever set_global_option is called.
pub fn registry(&self) -> &OptionRegistry
pub fn parser(&self) -> &ConfigParser
pub fn has_errors(&self) -> bool
pub fn errors(&self) -> &[ConfigError]
pub async fn save_session(&self, path: &str) -> Result<(), String>
pub async fn load_session(&mut self, path: &str) -> Result<(), String>
pub async fn create_task_config( &self, overrides: HashMap<String, OptionValue>, ) -> HashMap<String, OptionValue>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ConfigManager
impl !UnwindSafe for ConfigManager
impl Freeze for ConfigManager
impl Send for ConfigManager
impl Sync for ConfigManager
impl Unpin for ConfigManager
impl UnsafeUnpin for ConfigManager
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> 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