mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Use new format!
syntax where possible
(fix clippy)
This commit is contained in:
parent
867adbb20b
commit
4cae2c93cb
17 changed files with 49 additions and 53 deletions
|
@ -293,5 +293,5 @@ impl Bot {
|
|||
}
|
||||
|
||||
fn get_env(env: &'static str) -> String {
|
||||
std::env::var(env).unwrap_or_else(|_| panic!("Cannot get the {} env variable", env))
|
||||
std::env::var(env).unwrap_or_else(|_| panic!("Cannot get the {env} env variable"))
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ impl Doc {
|
|||
link.clear();
|
||||
*link += *value;
|
||||
} else if key.is_exact() {
|
||||
panic!("Patch error: {:?} doesn't have link {}", key, name);
|
||||
panic!("Patch error: {key:?} doesn't have link {name}");
|
||||
}
|
||||
}
|
||||
Patch::AddLink { name, value } => {
|
||||
|
@ -228,7 +228,7 @@ fn intra_links(doc: &mut Doc) {
|
|||
}
|
||||
_ => {
|
||||
repls_t.push(k.clone());
|
||||
*v = format!("crate::types::{}", k);
|
||||
*v = format!("crate::types::{k}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -236,23 +236,23 @@ fn intra_links(doc: &mut Doc) {
|
|||
|
||||
for repl in repls_t {
|
||||
if let Some(value) = doc.md_links.remove(repl.as_str()) {
|
||||
doc.md = doc.md.replace(format!("[{}]", repl).as_str(), &format!("[`{}`]", repl));
|
||||
doc.md_links.insert(format!("`{}`", repl), value);
|
||||
doc.md = doc.md.replace(format!("[{repl}]").as_str(), &format!("[`{repl}`]"));
|
||||
doc.md_links.insert(format!("`{repl}`"), value);
|
||||
}
|
||||
}
|
||||
|
||||
for repl in repls_m {
|
||||
if let Some(value) = doc.md_links.remove(repl.as_str()) {
|
||||
let repln = to_uppercase(&repl);
|
||||
doc.md = doc.md.replace(format!("[{}]", repl).as_str(), &format!("[`{}`]", repln));
|
||||
doc.md_links.insert(format!("`{}`", repln), value);
|
||||
doc.md = doc.md.replace(format!("[{repl}]").as_str(), &format!("[`{repln}`]"));
|
||||
doc.md_links.insert(format!("`{repln}`"), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn escape_kw(s: &mut String) {
|
||||
if ["type"].contains(&s.as_str()) {
|
||||
*s = format!("{}_", s);
|
||||
*s = format!("{s}_");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ fn patch_types(schema: &mut Schema, from: Type, to: Type, list: &[(&str, &str)])
|
|||
.find(|p| p.name == param)
|
||||
.expect("Couldn't find parameter for patching");
|
||||
|
||||
assert_eq!(p.ty, from, "{}::{}", method, param);
|
||||
assert_eq!(p.ty, from, "{method}::{param}");
|
||||
p.ty = to.clone();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,8 +97,8 @@ impl std::fmt::Display for Type {
|
|||
Type::f64 => write!(f, "f64"),
|
||||
Type::bool => write!(f, "bool"),
|
||||
Type::String => write!(f, "String"),
|
||||
Type::Option(inner) => write!(f, "Option<{}>", inner),
|
||||
Type::ArrayOf(inner) => write!(f, "Vec<{}>", inner),
|
||||
Type::Option(inner) => write!(f, "Option<{inner}>"),
|
||||
Type::ArrayOf(inner) => write!(f, "Vec<{inner}>"),
|
||||
Type::RawTy(raw) => f.write_str(raw),
|
||||
Type::Url => write!(f, "Url"),
|
||||
Type::DateTime => write!(f, "DateTime<Utc>"),
|
||||
|
|
|
@ -1305,12 +1305,12 @@ fn codegen_requester_forward() {
|
|||
.join(",\n ");
|
||||
|
||||
let generics =
|
||||
if generics.is_empty() { String::from("") } else { format!("<{}>", generics) };
|
||||
if generics.is_empty() { String::from("") } else { format!("<{generics}>") };
|
||||
|
||||
let where_clause = if where_clause.is_empty() {
|
||||
String::from("")
|
||||
} else {
|
||||
format!(" where {}", where_clause)
|
||||
format!(" where {where_clause}")
|
||||
};
|
||||
|
||||
format!(
|
||||
|
|
|
@ -80,16 +80,14 @@ pub fn default_reqwest_settings() -> reqwest::ClientBuilder {
|
|||
///
|
||||
/// [Telegram documentation]: https://core.telegram.org/bots/api#making-requests
|
||||
fn method_url(base: reqwest::Url, token: &str, method_name: &str) -> reqwest::Url {
|
||||
base.join(&format!("/bot{token}/{method}", token = token, method = method_name))
|
||||
.expect("failed to format url")
|
||||
base.join(&format!("/bot{token}/{method_name}")).expect("failed to format url")
|
||||
}
|
||||
|
||||
/// Creates URL for downloading a file. See the [Telegram documentation].
|
||||
///
|
||||
/// [Telegram documentation]: https://core.telegram.org/bots/api#file
|
||||
fn file_url(base: reqwest::Url, token: &str, file_path: &str) -> reqwest::Url {
|
||||
base.join(&format!("file/bot{token}/{file}", token = token, file = file_path))
|
||||
.expect("failed to format url")
|
||||
base.join(&format!("file/bot{token}/{file_path}")).expect("failed to format url")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -1294,12 +1294,12 @@ fn codegen_requester_methods() {
|
|||
.join(",\n ");
|
||||
|
||||
let generics =
|
||||
if generics.is_empty() { String::from("") } else { format!("<{}>", generics) };
|
||||
if generics.is_empty() { String::from("") } else { format!("<{generics}>") };
|
||||
|
||||
let where_clause = if where_clause.is_empty() {
|
||||
String::from("")
|
||||
} else {
|
||||
format!(" where {}", where_clause)
|
||||
format!(" where {where_clause}")
|
||||
};
|
||||
|
||||
format!(
|
||||
|
|
|
@ -25,11 +25,11 @@ impl ser::Error for Error {
|
|||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Custom(s) => write!(f, "Custom serde error: {}", s),
|
||||
Self::Custom(s) => write!(f, "Custom serde error: {s}"),
|
||||
Self::TopLevelNotStruct => write!(f, "Multipart supports only structs at top level"),
|
||||
Self::Fmt(inner) => write!(f, "Formatting error: {}", inner),
|
||||
Self::Io(inner) => write!(f, "Io error: {}", inner),
|
||||
Self::Json(inner) => write!(f, "Json (de)serialization error: {}", inner),
|
||||
Self::Fmt(inner) => write!(f, "Formatting error: {inner}"),
|
||||
Self::Io(inner) => write!(f, "Io error: {inner}"),
|
||||
Self::Json(inner) => write!(f, "Json (de)serialization error: {inner}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -472,9 +472,9 @@ impl SerializeStruct for JsonPartSerializer {
|
|||
Empty => {
|
||||
self.state = Rest;
|
||||
|
||||
write!(&mut self.buf, "{{\"{}\":{}", key, value)?
|
||||
write!(&mut self.buf, "{{\"{key}\":{value}")?
|
||||
}
|
||||
Rest => write!(&mut self.buf, ",\"{}\":{}", key, value)?,
|
||||
Rest => write!(&mut self.buf, ",\"{key}\":{value}")?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -511,9 +511,9 @@ impl SerializeSeq for JsonPartSerializer {
|
|||
Empty => {
|
||||
self.state = Rest;
|
||||
|
||||
write!(&mut self.buf, "[{}", value)?
|
||||
write!(&mut self.buf, "[{value}")?
|
||||
}
|
||||
Rest => write!(&mut self.buf, ",{}", value)?,
|
||||
Rest => write!(&mut self.buf, ",{value}")?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -62,7 +62,7 @@ impl ChatId {
|
|||
Channel((MAX_MARKED_CHANNEL_ID - id) as _)
|
||||
}
|
||||
id @ MIN_USER_ID..=MAX_USER_ID => User(UserId(id as _)),
|
||||
id => panic!("malformed chat id: {}", id),
|
||||
id => panic!("malformed chat id: {id}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
fn url(n: u32) -> reqwest::Url {
|
||||
reqwest::Url::parse(&format!("https://example.com/{n}", n = n)).unwrap()
|
||||
reqwest::Url::parse(&format!("https://example.com/{n}")).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -11,11 +11,11 @@ use crate::types::{ChatId, UserId};
|
|||
#[serde(untagged)]
|
||||
pub enum Recipient {
|
||||
/// A chat identifier.
|
||||
#[display(fmt = "{}", _0)]
|
||||
#[display(fmt = "{_0}")]
|
||||
Id(ChatId),
|
||||
|
||||
/// A channel username (in the format @channelusername).
|
||||
#[display(fmt = "{}", _0)]
|
||||
#[display(fmt = "{_0}")]
|
||||
ChannelUsername(String),
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ impl UserId {
|
|||
/// `tg://user/?id=<...>`.
|
||||
#[must_use]
|
||||
pub fn url(self) -> reqwest::Url {
|
||||
reqwest::Url::parse(&format!("tg://user/?id={}", self)).unwrap()
|
||||
reqwest::Url::parse(&format!("tg://user/?id={self}")).unwrap()
|
||||
}
|
||||
|
||||
/// Returns `true` if this is the id of the special user used by telegram
|
||||
|
|
|
@ -39,7 +39,7 @@ impl<S> SqliteStorage<S> {
|
|||
path: &str,
|
||||
serializer: S,
|
||||
) -> Result<Arc<Self>, SqliteStorageError<Infallible>> {
|
||||
let pool = SqlitePool::connect(format!("sqlite:{}?mode=rwc", path).as_str()).await?;
|
||||
let pool = SqlitePool::connect(format!("sqlite:{path}?mode=rwc").as_str()).await?;
|
||||
let mut conn = pool.acquire().await?;
|
||||
sqlx::query(
|
||||
r#"
|
||||
|
|
|
@ -56,7 +56,7 @@ where
|
|||
D: Send + 'static,
|
||||
{
|
||||
Box::pin(async move {
|
||||
let to = format!("{:#?}", dialogue);
|
||||
let to = format!("{dialogue:#?}");
|
||||
<S as Storage<D>>::update_dialogue(self.inner.clone(), chat_id, dialogue).await?;
|
||||
log::trace!("Updated a dialogue #{}: {:#?}", chat_id, to);
|
||||
Ok(())
|
||||
|
|
|
@ -429,18 +429,16 @@ impl Display for ParseError {
|
|||
match self {
|
||||
ParseError::TooFewArguments { expected, found, message } => write!(
|
||||
f,
|
||||
"Too few arguments (expected {}, found {}, message = '{}')",
|
||||
expected, found, message
|
||||
"Too few arguments (expected {expected}, found {found}, message = '{message}')"
|
||||
),
|
||||
ParseError::TooManyArguments { expected, found, message } => write!(
|
||||
f,
|
||||
"Too many arguments (expected {}, found {}, message = '{}')",
|
||||
expected, found, message
|
||||
"Too many arguments (expected {expected}, found {found}, message = '{message}')"
|
||||
),
|
||||
ParseError::IncorrectFormat(e) => write!(f, "Incorrect format of command args: {}", e),
|
||||
ParseError::UnknownCommand(e) => write!(f, "Unknown command: {}", e),
|
||||
ParseError::WrongBotName(n) => write!(f, "Wrong bot name: {}", n),
|
||||
ParseError::Custom(e) => write!(f, "{}", e),
|
||||
ParseError::IncorrectFormat(e) => write!(f, "Incorrect format of command args: {e}"),
|
||||
ParseError::UnknownCommand(e) => write!(f, "Unknown command: {e}"),
|
||||
ParseError::WrongBotName(n) => write!(f, "Wrong bot name: {n}"),
|
||||
ParseError::Custom(e) => write!(f, "{e}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use teloxide_core::types::User;
|
|||
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
|
||||
without using its output does nothing useful"]
|
||||
pub fn bold(s: &str) -> String {
|
||||
format!("<b>{}</b>", s)
|
||||
format!("<b>{s}</b>")
|
||||
}
|
||||
|
||||
/// Applies the italic font style to the string.
|
||||
|
@ -21,7 +21,7 @@ pub fn bold(s: &str) -> String {
|
|||
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
|
||||
without using its output does nothing useful"]
|
||||
pub fn italic(s: &str) -> String {
|
||||
format!("<i>{}</i>", s)
|
||||
format!("<i>{s}</i>")
|
||||
}
|
||||
|
||||
/// Applies the underline font style to the string.
|
||||
|
@ -31,7 +31,7 @@ pub fn italic(s: &str) -> String {
|
|||
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
|
||||
without using its output does nothing useful"]
|
||||
pub fn underline(s: &str) -> String {
|
||||
format!("<u>{}</u>", s)
|
||||
format!("<u>{s}</u>")
|
||||
}
|
||||
|
||||
/// Applies the strikethrough font style to the string.
|
||||
|
@ -41,7 +41,7 @@ pub fn underline(s: &str) -> String {
|
|||
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
|
||||
without using its output does nothing useful"]
|
||||
pub fn strike(s: &str) -> String {
|
||||
format!("<s>{}</s>", s)
|
||||
format!("<s>{s}</s>")
|
||||
}
|
||||
|
||||
/// Builds an inline link with an anchor.
|
||||
|
@ -57,7 +57,7 @@ pub fn link(url: &str, text: &str) -> String {
|
|||
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
|
||||
without using its output does nothing useful"]
|
||||
pub fn user_mention(user_id: i64, text: &str) -> String {
|
||||
link(format!("tg://user?id={}", user_id).as_str(), text)
|
||||
link(format!("tg://user?id={user_id}").as_str(), text)
|
||||
}
|
||||
|
||||
/// Formats the code block.
|
||||
|
|
|
@ -11,7 +11,7 @@ use teloxide_core::types::User;
|
|||
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
|
||||
without using its output does nothing useful"]
|
||||
pub fn bold(s: &str) -> String {
|
||||
format!("*{}*", s)
|
||||
format!("*{s}*")
|
||||
}
|
||||
|
||||
/// Applies the italic font style to the string.
|
||||
|
@ -25,7 +25,7 @@ pub fn italic(s: &str) -> String {
|
|||
if s.starts_with("__") && s.ends_with("__") {
|
||||
format!(r"_{}\r__", &s[..s.len() - 1])
|
||||
} else {
|
||||
format!("_{}_", s)
|
||||
format!("_{s}_")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,9 +43,9 @@ pub fn underline(s: &str) -> String {
|
|||
// ___italic underline_\r__, where \r is a character with code 13, which
|
||||
// will be ignored.
|
||||
if s.starts_with('_') && s.ends_with('_') {
|
||||
format!(r"__{}\r__", s)
|
||||
format!(r"__{s}\r__")
|
||||
} else {
|
||||
format!("__{}__", s)
|
||||
format!("__{s}__")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ pub fn underline(s: &str) -> String {
|
|||
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
|
||||
without using its output does nothing useful"]
|
||||
pub fn strike(s: &str) -> String {
|
||||
format!("~{}~", s)
|
||||
format!("~{s}~")
|
||||
}
|
||||
|
||||
/// Builds an inline link with an anchor.
|
||||
|
@ -72,7 +72,7 @@ pub fn link(url: &str, text: &str) -> String {
|
|||
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
|
||||
without using its output does nothing useful"]
|
||||
pub fn user_mention(user_id: i64, text: &str) -> String {
|
||||
link(format!("tg://user?id={}", user_id).as_str(), text)
|
||||
link(format!("tg://user?id={user_id}").as_str(), text)
|
||||
}
|
||||
|
||||
/// Formats the code block.
|
||||
|
|
Loading…
Reference in a new issue