Skip to content

Commit

Permalink
refactor: shorten variable name not as much
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Sep 10, 2024
1 parent 060cba1 commit 65ce914
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
6 changes: 2 additions & 4 deletions examples/async_reply_to_message_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ async fn process_message(message: Message, api: AsyncApi) {
let reply_parameters = ReplyParameters::builder()
.message_id(message.message_id)
.build();

let send_message_params = SendMessageParams::builder()
.chat_id(message.chat.id)
.text("hello")
.reply_parameters(reply_parameters)
.build();

if let Err(err) = api.send_message(&send_message_params).await {
println!("Failed to send message: {err:?}");
if let Err(error) = api.send_message(&send_message_params).await {
println!("Failed to send message: {error:?}");
}
}
6 changes: 2 additions & 4 deletions examples/reply_to_message_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ fn main() {
let reply_parameters = ReplyParameters::builder()
.message_id(message.message_id)
.build();

let send_message_params = SendMessageParams::builder()
.chat_id(message.chat.id)
.text("hello")
.reply_parameters(reply_parameters)
.build();

if let Err(err) = api.send_message(&send_message_params) {
println!("Failed to send message: {err:?}");
if let Err(error) = api.send_message(&send_message_params) {
println!("Failed to send message: {error:?}");
}
}
update_params.offset = Some(i64::from(update.update_id) + 1);
Expand Down
8 changes: 4 additions & 4 deletions src/api/async_telegram_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl AsyncApi {
where
Params: serde::ser::Serialize + std::fmt::Debug,
{
serde_json::to_string(params).map_err(|e| Error::Encode(format!("{e:?} : {params:?}")))
serde_json::to_string(params).map_err(|err| Error::Encode(format!("{err:?} : {params:?}")))
}

pub async fn decode_response<Output>(response: reqwest::Response) -> Result<Output, Error>
Expand All @@ -50,12 +50,12 @@ impl AsyncApi {
Err(Error::Api(Self::parse_json(&message)?))
}
}
Err(e) => Err(Error::Decode(format!("Failed to decode response: {e:?}"))),
Err(error) => Err(Error::Decode(format!("{error:?}"))),
}
}

fn parse_json<Output: serde::de::DeserializeOwned>(body: &str) -> Result<Output, Error> {
serde_json::from_str(body).map_err(|e| Error::Decode(format!("{e:?} : {body:?}")))
serde_json::from_str(body).map_err(|error| Error::Decode(format!("{error:?} : {body:?}")))
}
}

Expand Down Expand Up @@ -134,7 +134,7 @@ impl AsyncTelegramApi for AsyncApi {
for (parameter_name, file_path, file_name) in files_with_paths {
let file = File::open(file_path)
.await
.map_err(|err| Error::Encode(err.to_string()))?;
.map_err(|error| Error::Encode(error.to_string()))?;
let part = multipart::Part::stream(file).file_name(file_name);
form = form.part(parameter_name, part);
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/telegram_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Api {
where
Params: serde::ser::Serialize + std::fmt::Debug,
{
serde_json::to_string(params).map_err(|e| Error::Encode(format!("{e:?} : {params:?}")))
serde_json::to_string(params).map_err(|err| Error::Encode(format!("{err:?} : {params:?}")))
}

pub fn decode_response<Output>(response: Response) -> Result<Output, Error>
Expand All @@ -41,7 +41,7 @@ impl Api {
match response.into_string() {
Ok(message) => serde_json::from_str(&message)
.map_err(|error| Error::Decode(format!("{error:?} : {message:?}"))),
Err(e) => Err(Error::Decode(format!("Failed to decode response: {e:?}"))),
Err(error) => Err(Error::Decode(format!("{error:?}"))),
}
}
}
Expand Down

0 comments on commit 65ce914

Please sign in to comment.