Skip to main content

tui_torrent/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum TorrentError {
5    Network(reqwest::Error),
6    Parse(String),
7    NotFound(String),
8    Aria2(String),
9}
10
11impl fmt::Display for TorrentError {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        match self {
14            TorrentError::Network(e) => write!(f, "Network error: {}", e),
15            TorrentError::Parse(msg) => write!(f, "Parse error: {}", msg),
16            TorrentError::NotFound(msg) => write!(f, "Not found: {}", msg),
17            TorrentError::Aria2(msg) => write!(f, "Aria2 error: {}", msg),
18        }
19    }
20}
21
22impl std::error::Error for TorrentError {}
23
24impl From<reqwest::Error> for TorrentError {
25    fn from(error: reqwest::Error) -> Self {
26        TorrentError::Network(error)
27    }
28}
29
30pub type Result<T> = std::result::Result<T, TorrentError>;