From 484d1ccd83c357419e3c8298f2c538e8521bca5a Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 14 Mar 2022 18:21:57 +0400 Subject: [PATCH] Fixup documentation --- README.md | 6 +++--- src/utils/command.rs | 37 +++++++++++++++++++++---------------- src/utils/shutdown_token.rs | 4 ++++ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7acff473..81d3fc3a 100644 --- a/README.md +++ b/README.md @@ -125,11 +125,11 @@ Commands are strongly typed and defined declaratively, similar to how we define ([Full](examples/simple_commands.rs)) ```rust,no_run -use teloxide::{prelude2::*, utils::command::BotCommand}; +use teloxide::{prelude2::*, utils::command::BotCommands}; use std::error::Error; -#[derive(BotCommand, Clone)] +#[derive(BotCommands, Clone)] #[command(rename = "lowercase", description = "These commands are supported:")] enum Command { #[command(description = "display this text.")] @@ -146,7 +146,7 @@ async fn answer( command: Command, ) -> Result<(), Box> { match command { - Command::Help => bot.send_message(message.chat.id, Command::descriptions()).await?, + Command::Help => bot.send_message(message.chat.id, Command::descriptions().to_string()).await?, Command::Username(username) => { bot.send_message(message.chat.id, format!("Your username is @{}.", username)).await? } diff --git a/src/utils/command.rs b/src/utils/command.rs index e509f029..c2d962fc 100644 --- a/src/utils/command.rs +++ b/src/utils/command.rs @@ -1,17 +1,18 @@ //! Command parsers. //! -//! You can either create an `enum` with derived [`BotCommand`], containing +//! You can either create an `enum` with derived [`BotCommands`], containing //! commands of your bot, or use functions, which split input text into a string //! command with its arguments. //! -//! # Using BotCommand +//! # Using BotCommands +//! //! ``` //! # #[cfg(feature = "macros")] { -//! use teloxide::utils::command::BotCommand; +//! use teloxide::utils::command::BotCommands; //! //! type UnitOfTime = u8; //! -//! #[derive(BotCommand, PartialEq, Debug)] +//! #[derive(BotCommands, PartialEq, Debug)] //! #[command(rename = "lowercase", parse_with = "split")] //! enum AdminCommand { //! Mute(UnitOfTime, char), @@ -24,6 +25,7 @@ //! ``` //! //! # Using parse_command +//! //! ``` //! use teloxide::utils::command::parse_command; //! @@ -33,6 +35,7 @@ //! ``` //! //! # Using parse_command_with_prefix +//! //! ``` //! use teloxide::utils::command::parse_command_with_prefix; //! @@ -66,11 +69,11 @@ pub use teloxide_macros::BotCommands; /// # Example /// ``` /// # #[cfg(feature = "macros")] { -/// use teloxide::utils::command::BotCommand; +/// use teloxide::utils::command::BotCommands; /// /// type UnitOfTime = u8; /// -/// #[derive(BotCommand, PartialEq, Debug)] +/// #[derive(BotCommands, PartialEq, Debug)] /// #[command(rename = "lowercase", parse_with = "split")] /// enum AdminCommand { /// Mute(UnitOfTime, char), @@ -104,9 +107,9 @@ pub use teloxide_macros::BotCommands; /// ## Example /// ``` /// # #[cfg(feature = "macros")] { -/// use teloxide::utils::command::BotCommand; +/// use teloxide::utils::command::BotCommands; /// -/// #[derive(BotCommand, PartialEq, Debug)] +/// #[derive(BotCommands, PartialEq, Debug)] /// #[command(rename = "lowercase")] /// enum Command { /// Text(String), @@ -124,9 +127,9 @@ pub use teloxide_macros::BotCommands; /// ## Example /// ``` /// # #[cfg(feature = "macros")] { -/// use teloxide::utils::command::BotCommand; +/// use teloxide::utils::command::BotCommands; /// -/// #[derive(BotCommand, PartialEq, Debug)] +/// #[derive(BotCommands, PartialEq, Debug)] /// #[command(rename = "lowercase", parse_with = "split")] /// enum Command { /// Nums(u8, u16, i32), @@ -144,9 +147,9 @@ pub use teloxide_macros::BotCommands; /// ## Example /// ``` /// # #[cfg(feature = "macros")] { -/// use teloxide::utils::command::BotCommand; +/// use teloxide::utils::command::BotCommands; /// -/// #[derive(BotCommand, PartialEq, Debug)] +/// #[derive(BotCommands, PartialEq, Debug)] /// #[command(rename = "lowercase", parse_with = "split", separator = "|")] /// enum Command { /// Nums(u8, u16, i32), @@ -177,7 +180,7 @@ pub use teloxide_macros::BotCommands; /// ## Example /// ``` /// # #[cfg(feature = "macros")] { -/// use teloxide::utils::command::{BotCommand, ParseError}; +/// use teloxide::utils::command::{BotCommands, ParseError}; /// /// fn accept_two_digits(input: String) -> Result<(u8,), ParseError> { /// match input.len() { @@ -189,7 +192,7 @@ pub use teloxide_macros::BotCommands; /// } /// } /// -/// #[derive(BotCommand, PartialEq, Debug)] +/// #[derive(BotCommands, PartialEq, Debug)] /// #[command(rename = "lowercase")] /// enum Command { /// #[command(parse_with = "accept_two_digits")] @@ -242,9 +245,9 @@ pub trait BotCommands: Sized { pub type PrefixedBotCommand = String; pub type BotName = String; -/// Errors returned from [`BotCommand::parse`]. +/// Errors returned from [`BotCommands::parse`]. /// -/// [`BotCommand::parse`]: crate::utils::command::BotCommand::parse +/// [`BotCommands::parse`]: BotCommands::parse #[derive(Debug)] pub enum ParseError { TooFewArguments { @@ -313,6 +316,8 @@ impl<'a> CommandDescriptions<'a> { /// ## Examples /// /// ``` + /// use teloxide::utils::command::{CommandDescription, CommandDescriptions}; + /// /// let descriptions = CommandDescriptions::new(&[ /// CommandDescription { prefix: "/", command: "start", description: "start this bot" }, /// CommandDescription { prefix: "/", command: "help", description: "show this message" }, diff --git a/src/utils/shutdown_token.rs b/src/utils/shutdown_token.rs index 3c11c812..2447f6fd 100644 --- a/src/utils/shutdown_token.rs +++ b/src/utils/shutdown_token.rs @@ -13,6 +13,8 @@ use tokio::sync::Notify; use crate::dispatching::update_listeners::UpdateListener; /// A token which used to shutdown [`Dispatcher`]. +/// +/// [`Dispatcher`]: crate::dispatching::Dispatcher #[derive(Clone)] pub struct ShutdownToken { dispatcher_state: Arc, @@ -21,6 +23,8 @@ pub struct ShutdownToken { /// This error is returned from [`ShutdownToken::shutdown`] when trying to /// shutdown an idle [`Dispatcher`]. +/// +/// [`Dispatcher`]: crate::dispatching::Dispatcher #[derive(Debug)] pub struct IdleShutdownError;