Skip to main content

OptionHandler

Struct OptionHandler 

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

  1. Built-in defaults (from [DEFAULTS])
  2. Config file values (via [load_config_file])
  3. Command-line arguments (via [apply_args])
  4. 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

Source

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.

Source

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.

Source

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.

Source

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-key sets boolean to false
  • -o key=value (GNU style)

CLI arguments take precedence over config file values but can be overridden by explicit [set] calls.

Source

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::warn but do not cause an error return.
§Errors

Returns an error only if the file cannot be read (IO failure).

Source

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.

Source

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

Source

pub fn default_count(&self) -> usize

Return the number of built-in defaults.

Source

pub fn is_explicitly_set(&self, key: &str) -> bool

Check whether a specific key has been explicitly set (vs using default).

Source

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§

Source§

impl Default for OptionHandler

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