pub struct OptionHandler { /* private fields */ }Expand description
Centralized option handler with built-in defaults, config file parsing, CLI argument override support, and DownloadOptions conversion.
§Priority Order (lowest to highest)
- Built-in defaults (from [
DEFAULTS]) - Config file values (via [
load_config_file]) - Command-line arguments (via [
apply_args]) - Explicit [
set] calls
§Example
use aria2_core::option::{OptionHandler, OptionValue};
let mut h = OptionHandler::new();
assert_eq!(h.get("split").as_usize(), 5); // default
h.set("split", OptionValue::Usize(10));
assert_eq!(h.get("split").as_usize(), 10);Implementations§
Source§impl OptionHandler
impl OptionHandler
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new OptionHandler pre-populated with all built-in defaults.
Every default from [built_in_defaults] is copied into both options and
defaults. Subsequent mutations only affect options; defaults
remains immutable so fallback lookups always work.
Sourcepub fn set(&mut self, key: &str, value: OptionValue)
pub fn set(&mut self, key: &str, value: OptionValue)
Set an option value. Overwrites any existing value.
After calling set, subsequent calls to [get] will return the new
value instead of the default.
Sourcepub fn get(&self, key: &str) -> &OptionValue
pub fn get(&self, key: &str) -> &OptionValue
Get the current value for key.
Falls back to the built-in default if the key was never explicitly set
(or was removed). Returns OptionValue::None for completely unknown keys.
Sourcepub fn apply_args(&mut self, args: &[String])
pub fn apply_args(&mut self, args: &[String])
Override options from raw command-line arguments.
Parses common CLI patterns:
--key=value/--key:value--key value(value in next arg)--no-keysets boolean to false-o key=value(GNU style)
CLI arguments take precedence over config file values but can be
overridden by explicit [set] calls.
Sourcepub fn load_config_file(&mut self, path: &Path) -> Result<(), String>
pub fn load_config_file(&mut self, path: &Path) -> Result<(), String>
Load options from a .aria2rc config file.
File format:
# Comment lines start with #
key=value
key="value with spaces"
key=['val1', 'val2']
bool-key=true
number-key=42
float-key=3.14§Parse Rules
- Lines starting with
#are comments and skipped. - Blank lines are skipped.
key=value: auto-detect type (see [detect_value_type]).- Invalid lines produce warnings via
tracing::warnbut do not cause an error return.
§Errors
Returns an error only if the file cannot be read (IO failure).
Sourcepub fn to_download_options(&self) -> DownloadOptions
pub fn to_download_options(&self) -> DownloadOptions
Convert current options to a DownloadOptions struct suitable for
creating a download task.
Maps well-known option keys to their corresponding fields in
DownloadOptions. Unknown or unmapped keys are silently ignored.
Sourcepub fn to_map(&self) -> HashMap<String, OptionValue>
pub fn to_map(&self) -> HashMap<String, OptionValue>
Export all current options as a key-value map.
Useful for RPC responses and serialization. Returns a clone of the internal options map (including defaults for unset keys).
Sourcepub fn default_count(&self) -> usize
pub fn default_count(&self) -> usize
Return the number of built-in defaults.
Sourcepub fn is_explicitly_set(&self, key: &str) -> bool
pub fn is_explicitly_set(&self, key: &str) -> bool
Check whether a specific key has been explicitly set (vs using default).
Sourcepub fn reset_to_default(&mut self, key: &str)
pub fn reset_to_default(&mut self, key: &str)
Remove an explicitly-set option, reverting it to its default value.
After removal, [get] will return the built-in default again.