From 9944524e34d996d0ce594a9481508c2629434b27 Mon Sep 17 00:00:00 2001 From: p0lunin Date: Wed, 24 Jun 2020 19:18:12 +0300 Subject: [PATCH] added Box in IncorrectFormat error --- Cargo.toml | 2 +- src/utils/command.rs | 7 ++++--- tests/command.rs | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa05b06a..61f5217d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ futures = "0.3.1" pin-project = "0.4.6" serde_with_macros = "1.0.1" -teloxide-macros = { path="../teloxide-macros" } +teloxide-macros = { git="https://github.com/teloxide/teloxide-macros", branch="dev" } [dev-dependencies] smart-default = "0.6.0" diff --git a/src/utils/command.rs b/src/utils/command.rs index 6c8dc8a0..cababa95 100644 --- a/src/utils/command.rs +++ b/src/utils/command.rs @@ -154,8 +154,9 @@ pub use teloxide_macros::BotCommand; /// fn accept_two_digits(input: String) -> Result<(u8,), ParseError> { /// match input.len() { /// 2 => { -/// let num = -/// input.parse().map_err(|_| ParseError::IncorrectFormat)?; +/// let num = input +/// .parse::() +/// .map_err(|e| ParseError::IncorrectFormat(e.into()))?; /// Ok((num,)) /// } /// len => Err(ParseError::Custom( @@ -214,7 +215,7 @@ pub enum ParseError { /// Redirected from [`FromStr::from_str`]. /// /// [`FromStr::from_str`]: https://doc.rust-lang.org/std/str/trait.FromStr.html#tymethod.from_str - IncorrectFormat, + IncorrectFormat(Box), UnknownCommand(PrefixedBotCommand), WrongBotName(BotName), diff --git a/tests/command.rs b/tests/command.rs index bcb270b7..eadb214d 100644 --- a/tests/command.rs +++ b/tests/command.rs @@ -129,7 +129,11 @@ fn parse_custom_parser() { let vec = s.split_whitespace().collect::>(); let (left, right) = match vec.as_slice() { [l, r] => (l, r), - _ => return Err(ParseError::IncorrectFormat), + _ => { + return Err(ParseError::IncorrectFormat( + "might be 2 arguments!".into(), + )) + } }; left.parse::().map(|res| (res, right.to_string())).map_err(|_| { ParseError::Custom(