From 491d896cbd90859b4e26d00d49ee8df5c05b1339 Mon Sep 17 00:00:00 2001 From: EAimTY Date: Wed, 10 Nov 2021 19:10:09 +0900 Subject: [PATCH] update dep `bing-dict` to version `0.2` --- Cargo.toml | 6 +++--- src/handler/command.rs | 7 ++++--- src/handler/inline_query.rs | 7 ++++--- src/handler/message.rs | 7 ++++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7c029d1..688f245 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bing-dict-telegram-bot" description = "A Telegram bot uses Bing Dictionary to translate words and phrases from Chinese to English or English to Chinese" -version = "0.5.1" +version = "0.5.2" authors = ["EAimTY "] edition = "2021" readme = "README.md" @@ -9,13 +9,13 @@ license = "GPL-3.0-or-later" repository = "https://github.com/EAimTY/bing-dict-telegram-bot" [dependencies] -bing-dict = "0.1" +bing-dict = "0.2" futures-util = "0.3" getopts = "0.2" tgbot = "0.14" thiserror = "1.0" tinyset = "0.4" -tokio = { version = "1.11", features = ["rt-multi-thread", "macros"] } +tokio = { version = "1.13", features = ["rt-multi-thread", "macros"] } [profile.release] lto = true diff --git a/src/handler/command.rs b/src/handler/command.rs index 78d756f..0ec033b 100644 --- a/src/handler/command.rs +++ b/src/handler/command.rs @@ -61,9 +61,10 @@ impl Handler { if let Some(input) = input { let result = if !input.is_empty() { - bing_dict::translate(input) - .await? - .unwrap_or_else(|| String::from("No paraphrase found")) + bing_dict::translate(input).await?.map_or_else( + || String::from("No paraphrase found"), + |paraphrase| paraphrase.to_string(), + ) } else { String::from("No input") }; diff --git a/src/handler/inline_query.rs b/src/handler/inline_query.rs index 2f6e7f1..82d6ba4 100644 --- a/src/handler/inline_query.rs +++ b/src/handler/inline_query.rs @@ -15,9 +15,10 @@ impl Handler { let InlineQuery { id, query, .. } = inline_query; let inline_query_result = if !query.is_empty() { - let translate_result = bing_dict::translate(&query) - .await? - .unwrap_or_else(|| String::from("No paraphrase found")); + let translate_result = bing_dict::translate(&query).await?.map_or_else( + || String::from("No paraphrase found"), + |paraphrase| paraphrase.to_string(), + ); vec![InlineQueryResult::Article(InlineQueryResultArticle::new( query, diff --git a/src/handler/message.rs b/src/handler/message.rs index 6925a4b..ab4be02 100644 --- a/src/handler/message.rs +++ b/src/handler/message.rs @@ -29,9 +29,10 @@ impl Handler { if let Some(input) = input { let result = if !input.is_empty() { - bing_dict::translate(input) - .await? - .unwrap_or_else(|| String::from("No paraphrase found")) + bing_dict::translate(input).await?.map_or_else( + || String::from("No paraphrase found"), + |paraphrase| paraphrase.to_string(), + ) } else { String::from("No input") };