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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OptionHandler
impl RefUnwindSafe for OptionHandler
impl Send for OptionHandler
impl Sync for OptionHandler
impl Unpin for OptionHandler
impl UnsafeUnpin for OptionHandler
impl UnwindSafe for OptionHandler
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