From a6ce27051d94c9251566713a908b24287c28533c Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Tue, 10 Sep 2024 12:17:16 +0200 Subject: [PATCH] refactor(example): reduce name repetition --- examples/api_trait_implementation.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/api_trait_implementation.rs b/examples/api_trait_implementation.rs index 1f254bb..6eebf05 100644 --- a/examples/api_trait_implementation.rs +++ b/examples/api_trait_implementation.rs @@ -15,8 +15,8 @@ pub struct Api { #[derive(Debug)] pub enum Error { - HttpError { code: u16, message: String }, - ApiError(ErrorResponse), + Http { code: u16, message: String }, + Api(ErrorResponse), } impl Api { @@ -35,14 +35,14 @@ impl Api { impl From for Error { fn from(error: isahc::http::Error) -> Self { let message = format!("{error:?}"); - Self::HttpError { code: 500, message } + Self::Http { code: 500, message } } } impl From for Error { fn from(error: isahc::Error) -> Self { let message = format!("{error:?}"); - Self::HttpError { code: 500, message } + Self::Http { code: 500, message } } } @@ -66,7 +66,7 @@ impl TelegramApi for Api { } }; - let text = response.text().map_err(|error| Error::HttpError { + let text = response.text().map_err(|error| Error::Http { code: 500, message: error.to_string(), })?; @@ -74,8 +74,8 @@ impl TelegramApi for Api { let parsed_result: Result = serde_json::from_str(&text); parsed_result.map_err(|_| match serde_json::from_str::(&text) { - Ok(result) => Error::ApiError(result), - Err(error) => Error::HttpError { + Ok(result) => Error::Api(result), + Err(error) => Error::Http { code: 500, message: format!("{error:?}"), }, @@ -91,7 +91,7 @@ impl TelegramApi for Api { _files: Vec<(&str, PathBuf)>, ) -> Result { let message = "isahc doesn't support form data requests".to_string(); - Err(Error::HttpError { code: 500, message }) + Err(Error::Http { code: 500, message }) } }