1#![warn(clippy::pedantic)]
2#![forbid(unsafe_code)]
3
4pub use irelia_encoder;
11
12#[cfg(feature = "in_game")]
13pub mod in_game;
14#[cfg(feature = "rest")]
15pub mod rest;
16pub mod utils;
17#[cfg(feature = "ws")]
18pub mod ws;
19
20#[derive(Debug)]
24pub enum Error {
25 #[cfg(any(feature = "in_game", feature = "rest"))]
26 HyperHttpError(hyper::http::Error),
27 #[cfg(any(feature = "in_game", feature = "rest"))]
28 HyperClientError(hyper_util::client::legacy::Error),
29 #[cfg(any(feature = "in_game", feature = "rest"))]
30 HyperError(hyper::Error),
31 #[cfg(feature = "ws")]
32 WebsocketError(tokio_tungstenite::tungstenite::Error),
33 #[cfg(any(feature = "ws", feature = "rest"))]
34 StdIo(std::io::Error),
35 SerdeJsonError(serde_json::Error),
36 LCUProcessNotRunning,
37 PortNotFound,
38 AuthTokenNotFound,
39 LockFileNotFound,
40}
41
42#[cfg(any(feature = "in_game", feature = "rest"))]
43impl From<hyper::http::Error> for Error {
44 fn from(value: hyper::http::Error) -> Self {
45 Self::HyperHttpError(value)
46 }
47}
48
49#[cfg(any(feature = "in_game", feature = "rest"))]
50impl From<hyper_util::client::legacy::Error> for Error {
51 fn from(value: hyper_util::client::legacy::Error) -> Self {
52 Self::HyperClientError(value)
53 }
54}
55
56#[cfg(any(feature = "in_game", feature = "rest"))]
57impl From<hyper::Error> for Error {
58 fn from(value: hyper::Error) -> Self {
59 Self::HyperError(value)
60 }
61}
62
63#[cfg(feature = "ws")]
64impl From<tokio_tungstenite::tungstenite::Error> for Error {
65 fn from(value: tokio_tungstenite::tungstenite::Error) -> Self {
66 Self::WebsocketError(value)
67 }
68}
69
70impl From<serde_json::Error> for Error {
71 fn from(value: serde_json::Error) -> Self {
72 Self::SerdeJsonError(value)
73 }
74}
75
76impl From<std::io::Error> for Error {
77 fn from(value: std::io::Error) -> Self {
78 Self::StdIo(value)
79 }
80}
81
82impl std::fmt::Display for Error {
83 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84 let error = match self {
85 #[cfg(any(feature = "in_game", feature = "rest"))]
86 Error::HyperHttpError(err) => err.to_string(),
87 #[cfg(any(feature = "in_game", feature = "rest"))]
88 Error::HyperError(err) => err.to_string(),
89 #[cfg(any(feature = "in_game", feature = "rest"))]
90 Error::HyperClientError(err) => err.to_string(),
91 Error::SerdeJsonError(err) => err.to_string(),
92 #[cfg(feature = "ws")]
93 Error::WebsocketError(err) => err.to_string(),
94 Error::StdIo(err) => err.to_string(),
95 Error::LCUProcessNotRunning => String::from("LCU Process is not running!"),
96 Error::PortNotFound => String::from("Port Not Found!"),
97 Error::AuthTokenNotFound => String::from("Auth Token Not Found!"),
98 Error::LockFileNotFound => {
99 String::from("Unable to the lock file, but the process was running!")
100 }
101 };
102 f.write_str(&error)
103 }
104}
105
106impl std::error::Error for Error {}
107
108#[cfg(feature = "tauri")]
109impl serde::Serialize for Error {
110 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
111 where
112 S: serde::Serializer,
113 {
114 serializer.serialize_str(&self.to_string())
115 }
116}
117
118#[cfg(any(feature = "rest", feature = "in_game"))]
119pub use utils::requests::RequestClient;