mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
added Box<dyn Error> in IncorrectFormat error
This commit is contained in:
parent
e47a73088d
commit
9944524e34
3 changed files with 10 additions and 5 deletions
|
@ -45,7 +45,7 @@ futures = "0.3.1"
|
||||||
pin-project = "0.4.6"
|
pin-project = "0.4.6"
|
||||||
serde_with_macros = "1.0.1"
|
serde_with_macros = "1.0.1"
|
||||||
|
|
||||||
teloxide-macros = { path="../teloxide-macros" }
|
teloxide-macros = { git="https://github.com/teloxide/teloxide-macros", branch="dev" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
smart-default = "0.6.0"
|
smart-default = "0.6.0"
|
||||||
|
|
|
@ -154,8 +154,9 @@ pub use teloxide_macros::BotCommand;
|
||||||
/// fn accept_two_digits(input: String) -> Result<(u8,), ParseError> {
|
/// fn accept_two_digits(input: String) -> Result<(u8,), ParseError> {
|
||||||
/// match input.len() {
|
/// match input.len() {
|
||||||
/// 2 => {
|
/// 2 => {
|
||||||
/// let num =
|
/// let num = input
|
||||||
/// input.parse().map_err(|_| ParseError::IncorrectFormat)?;
|
/// .parse::<u8>()
|
||||||
|
/// .map_err(|e| ParseError::IncorrectFormat(e.into()))?;
|
||||||
/// Ok((num,))
|
/// Ok((num,))
|
||||||
/// }
|
/// }
|
||||||
/// len => Err(ParseError::Custom(
|
/// len => Err(ParseError::Custom(
|
||||||
|
@ -214,7 +215,7 @@ pub enum ParseError {
|
||||||
/// Redirected from [`FromStr::from_str`].
|
/// Redirected from [`FromStr::from_str`].
|
||||||
///
|
///
|
||||||
/// [`FromStr::from_str`]: https://doc.rust-lang.org/std/str/trait.FromStr.html#tymethod.from_str
|
/// [`FromStr::from_str`]: https://doc.rust-lang.org/std/str/trait.FromStr.html#tymethod.from_str
|
||||||
IncorrectFormat,
|
IncorrectFormat(Box<dyn Error>),
|
||||||
|
|
||||||
UnknownCommand(PrefixedBotCommand),
|
UnknownCommand(PrefixedBotCommand),
|
||||||
WrongBotName(BotName),
|
WrongBotName(BotName),
|
||||||
|
|
|
@ -129,7 +129,11 @@ fn parse_custom_parser() {
|
||||||
let vec = s.split_whitespace().collect::<Vec<_>>();
|
let vec = s.split_whitespace().collect::<Vec<_>>();
|
||||||
let (left, right) = match vec.as_slice() {
|
let (left, right) = match vec.as_slice() {
|
||||||
[l, r] => (l, r),
|
[l, r] => (l, r),
|
||||||
_ => return Err(ParseError::IncorrectFormat),
|
_ => {
|
||||||
|
return Err(ParseError::IncorrectFormat(
|
||||||
|
"might be 2 arguments!".into(),
|
||||||
|
))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
left.parse::<u8>().map(|res| (res, right.to_string())).map_err(|_| {
|
left.parse::<u8>().map(|res| (res, right.to_string())).map_err(|_| {
|
||||||
ParseError::Custom(
|
ParseError::Custom(
|
||||||
|
|
Loading…
Reference in a new issue