diff --git a/CHANGELOG.md b/CHANGELOG.md index 2198111f..6a82450e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## unreleased +## 0.10.1 - 2022-07-22 + +### Fixed + + - Mark the following functions with `#[must_use]` ([PR 457](https://github.com/teloxide/teloxide/pull/457)): + - `TraceStorage::into_inner`. + - `AsyncStopToken::new_pair`. + - `AsyncStopFlag::is_stopped`. + - All from `crate::utils::{html, markdown}`. + - Rendering of GIFs in lib.rs and crates.io ([PR 681](https://github.com/teloxide/teloxide/pull/681)). + ## 0.10.0 - 2022-07-21 ### Added diff --git a/Cargo.toml b/Cargo.toml index df04f34e..07661691 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "teloxide" -version = "0.10.0" +version = "0.10.1" edition = "2021" description = "An elegant Telegram bots framework for Rust" repository = "https://github.com/teloxide/teloxide" diff --git a/README.md b/README.md index b05f48f8..8ece9b1b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ > [v0.9 -> v0.10 migration guide >>](MIGRATION_GUIDE.md#09---010)
{}", escape(code)) } @@ -58,6 +72,8 @@ pub fn code_block(code: &str) -> String { /// Formats the code block with a specific language syntax. /// /// Escapes HTML characters inside the block. +#[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 code_block_with_lang(code: &str, lang: &str) -> String { format!( "
{}
",
@@ -69,6 +85,8 @@ pub fn code_block_with_lang(code: &str, lang: &str) -> String {
/// Formats the string as an inline code.
///
/// Escapes HTML characters inside the block.
+#[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 code_inline(s: &str) -> String {
format!("{}
", escape(s))
}
@@ -80,10 +98,14 @@ pub fn code_inline(s: &str) -> String {
/// they shoudn't be escaped by the [spec].
///
/// [spec]: https://core.telegram.org/bots/api#html-style
+#[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 escape(s: &str) -> String {
s.replace('&', "&").replace('<', "<").replace('>', ">")
}
+#[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_or_link(user: &User) -> String {
match user.mention() {
Some(mention) => mention,
diff --git a/src/utils/markdown.rs b/src/utils/markdown.rs
index 4419feb9..9c355444 100644
--- a/src/utils/markdown.rs
+++ b/src/utils/markdown.rs
@@ -8,6 +8,8 @@ use teloxide_core::types::User;
///
/// Passed string will not be automatically escaped because it can contain
/// nested markup.
+#[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)
}
@@ -17,6 +19,8 @@ pub fn bold(s: &str) -> String {
/// Can be safely used with `utils::markdown::underline()`.
/// Passed string will not be automatically escaped because it can contain
/// nested markup.
+#[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 {
if s.starts_with("__") && s.ends_with("__") {
format!(r"_{}\r__", &s[..s.len() - 1])
@@ -30,6 +34,8 @@ pub fn italic(s: &str) -> String {
/// Can be safely used with `utils::markdown::italic()`.
/// Passed string will not be automatically escaped because it can contain
/// nested markup.
+#[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 {
// In case of ambiguity between italic and underline entities
// ‘__’ is always greadily treated from left to right as beginning or end of
@@ -47,6 +53,8 @@ pub fn underline(s: &str) -> String {
///
/// Passed string will not be automatically escaped because it can contain
/// nested markup.
+#[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)
}
@@ -54,11 +62,15 @@ pub fn strike(s: &str) -> String {
/// Builds an inline link with an anchor.
///
/// Escapes `)` and ``` characters inside the link url.
+#[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 link(url: &str, text: &str) -> String {
format!("[{}]({})", text, escape_link_url(url))
}
/// Builds an inline user mention link with an anchor.
+#[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)
}
@@ -66,6 +78,8 @@ pub fn user_mention(user_id: i64, text: &str) -> String {
/// Formats the code block.
///
/// Escapes ``` and `\` characters inside the block.
+#[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 code_block(code: &str) -> String {
format!("```\n{}\n```", escape_code(code))
}
@@ -73,6 +87,8 @@ pub fn code_block(code: &str) -> String {
/// Formats the code block with a specific language syntax.
///
/// Escapes ``` and `\` characters inside the block.
+#[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 code_block_with_lang(code: &str, lang: &str) -> String {
format!("```{}\n{}\n```", escape(lang), escape_code(code))
}
@@ -80,6 +96,8 @@ pub fn code_block_with_lang(code: &str, lang: &str) -> String {
/// Formats the string as an inline code.
///
/// Escapes ``` and `\` characters inside the block.
+#[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 code_inline(s: &str) -> String {
format!("`{}`", escape_code(s))
}
@@ -88,6 +106,8 @@ pub fn code_inline(s: &str) -> String {
/// v2][spec] message style.
///
/// [spec]: https://core.telegram.org/bots/api#html-style
+#[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 escape(s: &str) -> String {
s.replace('_', r"\_")
.replace('*', r"\*")
@@ -111,16 +131,22 @@ pub fn escape(s: &str) -> String {
/// Escapes all markdown special characters specific for the inline link URL
/// (``` and `)`).
+#[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 escape_link_url(s: &str) -> String {
s.replace('`', r"\`").replace(')', r"\)")
}
/// Escapes all markdown special characters specific for the code block (``` and
/// `\`).
+#[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 escape_code(s: &str) -> String {
s.replace('\\', r"\\").replace('`', r"\`")
}
+#[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_or_link(user: &User) -> String {
match user.mention() {
Some(mention) => mention,