Skip to main content

ConfigManager

Struct ConfigManager 

Source
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:

  1. Built-in defaults (from OptionRegistry)
  2. Environment variables (ARIA2_* prefix)
  3. Configuration file (~/.aria2/aria2.conf)
  4. 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

Source

pub fn new() -> Self

Create a new ConfigManager with the built-in OptionRegistry containing ~95 core aria2 options.

Source

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).

Source

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.

Source

pub async fn load_file(&mut self, path: &str)

Load options from an aria2.conf-format configuration file.

Source

pub async fn load_env(&mut self)

Load options from environment variables with ARIA2_ prefix.

Maps ARIA2_SPLITsplit, ARIA2_DIRdir, etc.

Source

pub async fn get_global_option(&self, name: &str) -> Option<OptionValue>

Get a global option value by name.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn get_all_global_options(&self) -> HashMap<String, OptionValue>

Source

pub async fn get_all_global_options_json(&self) -> Value

Source

pub async fn get_task_default( &self, gid: &str, name: &str, ) -> Option<OptionValue>

Source

pub async fn set_task_option( &mut self, gid: &str, name: &str, value: OptionValue, ) -> Result<(), String>

Source

pub async fn change_task_options( &mut self, gid: &str, options: HashMap<String, String>, ) -> Vec<String>

Source

pub async fn get_task_options(&self, gid: &str) -> HashMap<String, OptionValue>

Source

pub async fn remove_task(&mut self, gid: &str)

Source

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.

Source

pub fn registry(&self) -> &OptionRegistry

Source

pub fn parser(&self) -> &ConfigParser

Source

pub fn has_errors(&self) -> bool

Source

pub fn errors(&self) -> &[ConfigError]

Source

pub async fn save_session(&self, path: &str) -> Result<(), String>

Source

pub async fn load_session(&mut self, path: &str) -> Result<(), String>

Source

pub async fn create_task_config( &self, overrides: HashMap<String, OptionValue>, ) -> HashMap<String, OptionValue>

Trait Implementations§

Source§

impl Default for ConfigManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more