Skip to main content

llama_server/
error.rs

1use std::io;
2use std::sync::Arc;
3
4/// An error.
5#[derive(Debug, Clone)]
6pub enum Error {
7    /// Some input/ouput operation failed.
8    IOFailed(Arc<io::Error>),
9    /// Some HTTP request failed.
10    RequestFailed(Arc<reqwest::Error>),
11}
12
13impl From<io::Error> for Error {
14    fn from(error: io::Error) -> Self {
15        Self::IOFailed(Arc::new(error))
16    }
17}
18
19impl From<Error> for io::Error {
20    fn from(error: Error) -> Self {
21        match error {
22            Error::IOFailed(error) => io::Error::new(error.kind(), error),
23            Error::RequestFailed(error) => io::Error::other(error),
24        }
25    }
26}
27
28impl From<reqwest::Error> for Error {
29    fn from(error: reqwest::Error) -> Self {
30        Self::RequestFailed(Arc::new(error))
31    }
32}
33
34impl From<tokio::task::JoinError> for Error {
35    fn from(error: tokio::task::JoinError) -> Self {
36        Error::IOFailed(Arc::new(io::Error::other(error)))
37    }
38}
39
40impl From<zip::result::ZipError> for Error {
41    fn from(error: zip::result::ZipError) -> Self {
42        Error::IOFailed(Arc::new(io::Error::other(error)))
43    }
44}