Fixup documentation

This commit is contained in:
Maybe Waffle 2022-03-14 18:21:57 +04:00
parent 86cc3d782f
commit 484d1ccd83
3 changed files with 28 additions and 19 deletions

View file

@ -125,11 +125,11 @@ Commands are strongly typed and defined declaratively, similar to how we define
([Full](examples/simple_commands.rs)) ([Full](examples/simple_commands.rs))
```rust,no_run ```rust,no_run
use teloxide::{prelude2::*, utils::command::BotCommand}; use teloxide::{prelude2::*, utils::command::BotCommands};
use std::error::Error; use std::error::Error;
#[derive(BotCommand, Clone)] #[derive(BotCommands, Clone)]
#[command(rename = "lowercase", description = "These commands are supported:")] #[command(rename = "lowercase", description = "These commands are supported:")]
enum Command { enum Command {
#[command(description = "display this text.")] #[command(description = "display this text.")]
@ -146,7 +146,7 @@ async fn answer(
command: Command, command: Command,
) -> Result<(), Box<dyn Error + Send + Sync>> { ) -> Result<(), Box<dyn Error + Send + Sync>> {
match command { 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) => { Command::Username(username) => {
bot.send_message(message.chat.id, format!("Your username is @{}.", username)).await? bot.send_message(message.chat.id, format!("Your username is @{}.", username)).await?
} }

View file

@ -1,17 +1,18 @@
//! Command parsers. //! 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 //! commands of your bot, or use functions, which split input text into a string
//! command with its arguments. //! command with its arguments.
//! //!
//! # Using BotCommand //! # Using BotCommands
//!
//! ``` //! ```
//! # #[cfg(feature = "macros")] { //! # #[cfg(feature = "macros")] {
//! use teloxide::utils::command::BotCommand; //! use teloxide::utils::command::BotCommands;
//! //!
//! type UnitOfTime = u8; //! type UnitOfTime = u8;
//! //!
//! #[derive(BotCommand, PartialEq, Debug)] //! #[derive(BotCommands, PartialEq, Debug)]
//! #[command(rename = "lowercase", parse_with = "split")] //! #[command(rename = "lowercase", parse_with = "split")]
//! enum AdminCommand { //! enum AdminCommand {
//! Mute(UnitOfTime, char), //! Mute(UnitOfTime, char),
@ -24,6 +25,7 @@
//! ``` //! ```
//! //!
//! # Using parse_command //! # Using parse_command
//!
//! ``` //! ```
//! use teloxide::utils::command::parse_command; //! use teloxide::utils::command::parse_command;
//! //!
@ -33,6 +35,7 @@
//! ``` //! ```
//! //!
//! # Using parse_command_with_prefix //! # Using parse_command_with_prefix
//!
//! ``` //! ```
//! use teloxide::utils::command::parse_command_with_prefix; //! use teloxide::utils::command::parse_command_with_prefix;
//! //!
@ -66,11 +69,11 @@ pub use teloxide_macros::BotCommands;
/// # Example /// # Example
/// ``` /// ```
/// # #[cfg(feature = "macros")] { /// # #[cfg(feature = "macros")] {
/// use teloxide::utils::command::BotCommand; /// use teloxide::utils::command::BotCommands;
/// ///
/// type UnitOfTime = u8; /// type UnitOfTime = u8;
/// ///
/// #[derive(BotCommand, PartialEq, Debug)] /// #[derive(BotCommands, PartialEq, Debug)]
/// #[command(rename = "lowercase", parse_with = "split")] /// #[command(rename = "lowercase", parse_with = "split")]
/// enum AdminCommand { /// enum AdminCommand {
/// Mute(UnitOfTime, char), /// Mute(UnitOfTime, char),
@ -104,9 +107,9 @@ pub use teloxide_macros::BotCommands;
/// ## Example /// ## Example
/// ``` /// ```
/// # #[cfg(feature = "macros")] { /// # #[cfg(feature = "macros")] {
/// use teloxide::utils::command::BotCommand; /// use teloxide::utils::command::BotCommands;
/// ///
/// #[derive(BotCommand, PartialEq, Debug)] /// #[derive(BotCommands, PartialEq, Debug)]
/// #[command(rename = "lowercase")] /// #[command(rename = "lowercase")]
/// enum Command { /// enum Command {
/// Text(String), /// Text(String),
@ -124,9 +127,9 @@ pub use teloxide_macros::BotCommands;
/// ## Example /// ## Example
/// ``` /// ```
/// # #[cfg(feature = "macros")] { /// # #[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")] /// #[command(rename = "lowercase", parse_with = "split")]
/// enum Command { /// enum Command {
/// Nums(u8, u16, i32), /// Nums(u8, u16, i32),
@ -144,9 +147,9 @@ pub use teloxide_macros::BotCommands;
/// ## Example /// ## Example
/// ``` /// ```
/// # #[cfg(feature = "macros")] { /// # #[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 = "|")] /// #[command(rename = "lowercase", parse_with = "split", separator = "|")]
/// enum Command { /// enum Command {
/// Nums(u8, u16, i32), /// Nums(u8, u16, i32),
@ -177,7 +180,7 @@ pub use teloxide_macros::BotCommands;
/// ## Example /// ## Example
/// ``` /// ```
/// # #[cfg(feature = "macros")] { /// # #[cfg(feature = "macros")] {
/// use teloxide::utils::command::{BotCommand, ParseError}; /// use teloxide::utils::command::{BotCommands, ParseError};
/// ///
/// fn accept_two_digits(input: String) -> Result<(u8,), ParseError> { /// fn accept_two_digits(input: String) -> Result<(u8,), ParseError> {
/// match input.len() { /// match input.len() {
@ -189,7 +192,7 @@ pub use teloxide_macros::BotCommands;
/// } /// }
/// } /// }
/// ///
/// #[derive(BotCommand, PartialEq, Debug)] /// #[derive(BotCommands, PartialEq, Debug)]
/// #[command(rename = "lowercase")] /// #[command(rename = "lowercase")]
/// enum Command { /// enum Command {
/// #[command(parse_with = "accept_two_digits")] /// #[command(parse_with = "accept_two_digits")]
@ -242,9 +245,9 @@ pub trait BotCommands: Sized {
pub type PrefixedBotCommand = String; pub type PrefixedBotCommand = String;
pub type BotName = 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)] #[derive(Debug)]
pub enum ParseError { pub enum ParseError {
TooFewArguments { TooFewArguments {
@ -313,6 +316,8 @@ impl<'a> CommandDescriptions<'a> {
/// ## Examples /// ## Examples
/// ///
/// ``` /// ```
/// use teloxide::utils::command::{CommandDescription, CommandDescriptions};
///
/// let descriptions = CommandDescriptions::new(&[ /// let descriptions = CommandDescriptions::new(&[
/// CommandDescription { prefix: "/", command: "start", description: "start this bot" }, /// CommandDescription { prefix: "/", command: "start", description: "start this bot" },
/// CommandDescription { prefix: "/", command: "help", description: "show this message" }, /// CommandDescription { prefix: "/", command: "help", description: "show this message" },

View file

@ -13,6 +13,8 @@ use tokio::sync::Notify;
use crate::dispatching::update_listeners::UpdateListener; use crate::dispatching::update_listeners::UpdateListener;
/// A token which used to shutdown [`Dispatcher`]. /// A token which used to shutdown [`Dispatcher`].
///
/// [`Dispatcher`]: crate::dispatching::Dispatcher
#[derive(Clone)] #[derive(Clone)]
pub struct ShutdownToken { pub struct ShutdownToken {
dispatcher_state: Arc<DispatcherState>, dispatcher_state: Arc<DispatcherState>,
@ -21,6 +23,8 @@ pub struct ShutdownToken {
/// This error is returned from [`ShutdownToken::shutdown`] when trying to /// This error is returned from [`ShutdownToken::shutdown`] when trying to
/// shutdown an idle [`Dispatcher`]. /// shutdown an idle [`Dispatcher`].
///
/// [`Dispatcher`]: crate::dispatching::Dispatcher
#[derive(Debug)] #[derive(Debug)]
pub struct IdleShutdownError; pub struct IdleShutdownError;