Skip to main content

ServerStatMan

Struct ServerStatMan 

Source
pub struct ServerStatMan { /* private fields */ }

Implementations§

Source§

impl ServerStatMan

Source

pub fn new() -> Self

Source

pub fn get_or_create(&self, host: &str) -> Arc<ServerStat>

Source

pub fn find_stat(&self, host: &str) -> Option<Arc<ServerStat>>

Source

pub fn update(&self, host: &str, dl_speed: u64, is_multi: bool)

Source

pub fn get_all_stats(&self) -> Vec<Arc<ServerStat>>

Source

pub fn remove(&self, host: &str)

Source

pub fn count(&self) -> usize

Source

pub fn hosts(&self) -> Vec<String>

Source

pub fn mark_failure(&self, host: &str, error_code: u16)

Mark a host as failed, updating error tracking fields.

Clones the existing ServerStat, applies failure info via set_failure_info, and replaces the entry in the map so all future Arc holders see the update.

Source

pub fn save_to_file(&self, path: &Path) -> Result<usize, String>

Save all server statistics to a JSON file (synchronous version).

Serializes all server statistics to a JSON file at the specified path. The file format includes version info, timestamp, and all server stats.

§Arguments
  • path - File path to save to (e.g., “server-stat.json”)
§Returns
  • Ok(usize) - Number of servers saved
  • Err(String) - Error message if save fails
§Example
use aria2_core::selector::server_stat_man::ServerStatMan;
use std::path::Path;

let man = ServerStatMan::new();
man.update("mirror.example.com", 5000, false);

let saved = man.save_to_file(Path::new("server-stat.json")).unwrap();
println!("Saved {} servers", saved);
Source

pub fn load_from_file(&self, path: &Path) -> Result<usize, String>

Load server statistics from a JSON file (synchronous version).

Reads a JSON file and restores all server statistics into memory. Existing statistics are preserved; loaded stats are merged in.

§Arguments
  • path - File path to load from
§Returns
  • Ok(usize) - Number of servers loaded
  • Err(String) - Error message if load fails
§Behavior
  • Returns Ok(0) if the file doesn’t exist (not an error)
  • Returns error if file exists but is invalid JSON
  • Merges with existing stats (doesn’t clear current stats)
§Example
use aria2_core::selector::server_stat_man::ServerStatMan;
use std::path::Path;

let man = ServerStatMan::new();
let loaded = man.load_from_file(Path::new("server-stat.json")).unwrap();
println!("Loaded {} servers", loaded);
Source

pub async fn save_to_file_async(&self, path: &Path) -> Result<usize, String>

Save all server statistics to a JSON file (async version).

Async variant of save_to_file() for use in async contexts. This is the preferred method when called from async code.

§Arguments
  • path - File path to save to
§Returns
  • Ok(usize) - Number of servers saved
  • Err(String) - Error message if save fails
Source

pub async fn load_from_file_async(&self, path: &Path) -> Result<usize, String>

Load server statistics from a JSON file (async version).

Async variant of load_from_file() for use in async contexts. This is the preferred method when called from async code.

§Arguments
  • path - File path to load from
§Returns
  • Ok(usize) - Number of servers loaded
  • Err(String) - Error message if load fails

Trait Implementations§

Source§

impl Default for ServerStatMan

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