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