More #[must_use] functions.

Former-commit-id: df58faab97
This commit is contained in:
Hirrolot 2022-10-02 10:15:20 +06:00
parent cdd5ac94ef
commit 567cd9ced5
4 changed files with 20 additions and 8 deletions

View file

@ -9,15 +9,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
<!-- TODO: use a version once teloxide-macros is released -->
- Updated `teloxide-macros` see its [changelog](https://github.com/teloxide/teloxide-macros/blob/master/CHANGELOG.md#unreleased) for more
- `UpdateListener` now has an associated type `Err` instead of a generic
- `AsUpdateStream` now has an associated type `StreamErr` instead of a generic
- Rename `dispatching::stop_token::{AsyncStopToken, AsyncStopFlag}` => `stop::{StopToken, StopFlag}`
- Updated `teloxide-macros` see its [changelog](https://github.com/teloxide/teloxide-macros/blob/master/CHANGELOG.md#unreleased) for more
- `UpdateListener` now has an associated type `Err` instead of a generic
- `AsUpdateStream` now has an associated type `StreamErr` instead of a generic
- Rename `dispatching::stop_token::{AsyncStopToken, AsyncStopFlag}` => `stop::{StopToken, StopFlag}`
- The following functions are now `#[must_use]`:
- `BotCommands::ty`.
- `CommandDescriptions::{new, global_description, username, username_from_me}`.
- `teloxide::filter_command`.
- `teloxide::dispatching::dialogue::enter`.
### Removed
- `dispatching::stop_token::StopToken` trait (all uses are replaced with `stop::StopToken` structure)
- Some previously deprecated items
- `dispatching::stop_token::StopToken` trait (all uses are replaced with `stop::StopToken` structure)
- Some previously deprecated items
- `enable_logging!`, `enable_logging_with_filter!`
- `HandlerFactory`, `HandlerExt::dispatch_by`

View file

@ -211,6 +211,7 @@ where
/// - `Upd`
///
/// [`HandlerExt::enter_dialogue`]: super::HandlerExt::enter_dialogue
#[must_use]
pub fn enter<Upd, S, D, Output>() -> Handler<'static, DependencyMap, Output, DpHandlerDescription>
where
S: Storage<D> + ?Sized + Send + Sync + 'static,

View file

@ -82,6 +82,7 @@ where
///
/// - [`crate::types::Message`]
/// - [`crate::types::Me`]
#[must_use]
pub fn filter_command<C, Output>() -> Handler<'static, DependencyMap, Output, DpHandlerDescription>
where
C: BotCommands + Send + Sync + 'static,

View file

@ -235,6 +235,7 @@ pub trait BotCommands: Sized {
/// Returns `PhantomData<Self>` that is used as a param of [`commands_repl`]
///
/// [`commands_repl`]: (crate::repls2::commands_repl)
#[must_use]
fn ty() -> PhantomData<Self> {
PhantomData
}
@ -296,11 +297,13 @@ pub struct CommandDescription<'a> {
impl<'a> CommandDescriptions<'a> {
/// Creates new [`CommandDescriptions`] from a list of command descriptions.
#[must_use]
pub fn new(descriptions: &'a [CommandDescription<'a>]) -> Self {
Self { global_description: None, descriptions, bot_username: None }
}
/// Sets the global description of these commands.
#[must_use]
pub fn global_description(self, global_description: &'a str) -> Self {
Self { global_description: Some(global_description), ..self }
}
@ -328,6 +331,7 @@ impl<'a> CommandDescriptions<'a> {
/// message"
/// );
/// ```
#[must_use]
pub fn username(self, bot_username: &'a str) -> Self {
Self { bot_username: Some(bot_username), ..self }
}
@ -338,6 +342,7 @@ impl<'a> CommandDescriptions<'a> {
/// method to get the username.
///
/// [`username`]: self::CommandDescriptions::username
#[must_use]
pub fn username_from_me(self, me: &'a Me) -> CommandDescriptions<'a> {
self.username(me.user.username.as_deref().expect("Bots must have usernames"))
}