pub struct ServerStatMan { /* private fields */ }Implementations§
Source§impl ServerStatMan
impl ServerStatMan
pub fn new() -> Self
pub fn get_or_create(&self, host: &str) -> Arc<ServerStat> ⓘ
pub fn find_stat(&self, host: &str) -> Option<Arc<ServerStat>>
pub fn update(&self, host: &str, dl_speed: u64, is_multi: bool)
pub fn get_all_stats(&self) -> Vec<Arc<ServerStat>>
pub fn remove(&self, host: &str)
pub fn count(&self) -> usize
pub fn hosts(&self) -> Vec<String>
Sourcepub fn mark_failure(&self, host: &str, error_code: u16)
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.
Sourcepub fn save_to_file(&self, path: &Path) -> Result<usize, String>
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 savedErr(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);Sourcepub fn load_from_file(&self, path: &Path) -> Result<usize, String>
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 loadedErr(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);Sourcepub async fn save_to_file_async(&self, path: &Path) -> Result<usize, String>
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 savedErr(String)- Error message if save fails
Sourcepub async fn load_from_file_async(&self, path: &Path) -> Result<usize, String>
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 loadedErr(String)- Error message if load fails
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ServerStatMan
impl RefUnwindSafe for ServerStatMan
impl Send for ServerStatMan
impl Sync for ServerStatMan
impl Unpin for ServerStatMan
impl UnsafeUnpin for ServerStatMan
impl UnwindSafe for ServerStatMan
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