refactor max_args error message

This commit is contained in:
ConnorSkees 2020-04-05 20:19:46 -04:00
parent a8ab6b1675
commit 49aa66eb78

View File

@ -37,21 +37,18 @@ macro_rules! named_arg {
macro_rules! max_args { macro_rules! max_args {
($args:ident, $count:literal) => { ($args:ident, $count:literal) => {
if $args.len() > $count { if $args.len() > $count {
let mut err = String::with_capacity(50);
err.push_str(&format!("Only {} argument", $count));
if $count != 1 { if $count != 1 {
return Err(format!( err.push('s');
"Only {} arguments allowed, but {} were passed.",
$count,
$args.len()
)
.into());
} else {
return Err(format!(
"Only {} argument allowed, but {} were passed.",
$count,
$args.len()
)
.into());
} }
err.push_str(&format!(" allowed, but {} ", $args.len()));
if $args.len() == 1 {
err.push_str("was passed.")
} else {
err.push_str("were passed.")
}
return Err(err.into());
} }
}; };
} }