Skip to content

Commit

Permalink
perf: further debloating by removing generics from error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Jan 9, 2018
1 parent 7ac5a5a commit eb8d919
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions src/errors.rs
Expand Up @@ -8,7 +8,7 @@ use std::process;
use std::result::Result as StdResult;

// Internal
use args::{AnyArg, FlagBuilder};
use args::AnyArg;
use fmt::{ColorWhen, Colorizer, ColorizerOption};
use suggestions;

Expand Down Expand Up @@ -404,14 +404,13 @@ impl Error {
pub fn write_to<W: Write>(&self, w: &mut W) -> io::Result<()> { write!(w, "{}", self.message) }

#[doc(hidden)]
pub fn argument_conflict<'a, 'b, A, O, U>(
arg: &A,
pub fn argument_conflict<'a, 'b, O, U>(
arg: &AnyArg,
other: Option<O>,
usage: U,
color: ColorWhen,
) -> Self
where
A: AnyArg<'a, 'b> + Display,
O: Into<String>,
U: Display,
{
Expand Down Expand Up @@ -444,9 +443,8 @@ impl Error {
}

#[doc(hidden)]
pub fn empty_value<'a, 'b, A, U>(arg: &A, usage: U, color: ColorWhen) -> Self
pub fn empty_value<'a, 'b, U>(arg: &AnyArg, usage: U, color: ColorWhen) -> Self
where
A: AnyArg<'a, 'b> + Display,
U: Display,
{
let c = Colorizer::new(ColorizerOption {
Expand All @@ -470,17 +468,16 @@ impl Error {
}

#[doc(hidden)]
pub fn invalid_value<'a, 'b, B, G, A, U>(
pub fn invalid_value<'a, 'b, B, G, U>(
bad_val: B,
good_vals: &[G],
arg: &A,
arg: &AnyArg,
usage: U,
color: ColorWhen,
) -> Self
where
B: AsRef<str>,
G: AsRef<str> + Display,
A: AnyArg<'a, 'b> + Display,
U: Display,
{
let c = Colorizer::new(ColorizerOption {
Expand Down Expand Up @@ -660,10 +657,9 @@ impl Error {
}

#[doc(hidden)]
pub fn too_many_values<'a, 'b, V, A, U>(val: V, arg: &A, usage: U, color: ColorWhen) -> Self
pub fn too_many_values<'a, 'b, V, U>(val: V, arg: &AnyArg, usage: U, color: ColorWhen) -> Self
where
V: AsRef<str> + Display + ToOwned,
A: AnyArg<'a, 'b> + Display,
U: Display,
{
let v = val.as_ref();
Expand All @@ -689,15 +685,14 @@ impl Error {
}

#[doc(hidden)]
pub fn too_few_values<'a, 'b, A, U>(
arg: &A,
pub fn too_few_values<'a, 'b, U>(
arg: &AnyArg,
min_vals: u64,
curr_vals: usize,
usage: U,
color: ColorWhen,
) -> Self
where
A: AnyArg<'a, 'b> + Display,
U: Display,
{
let c = Colorizer::new(ColorizerOption {
Expand All @@ -724,9 +719,7 @@ impl Error {
}

#[doc(hidden)]
pub fn value_validation<'a, 'b, A>(arg: Option<&A>, err: String, color: ColorWhen) -> Self
where
A: AnyArg<'a, 'b> + Display,
pub fn value_validation<'a, 'b>(arg: Option<&AnyArg>, err: String, color: ColorWhen) -> Self
{
let c = Colorizer::new(ColorizerOption {
use_stderr: true,
Expand All @@ -750,21 +743,20 @@ impl Error {

#[doc(hidden)]
pub fn value_validation_auto(err: String) -> Self {
let n: Option<&FlagBuilder> = None;
let n: Option<&AnyArg> = None;
Error::value_validation(n, err, ColorWhen::Auto)
}

#[doc(hidden)]
pub fn wrong_number_of_values<'a, 'b, A, S, U>(
arg: &A,
pub fn wrong_number_of_values<'a, 'b, S, U>(
arg: &AnyArg,
num_vals: u64,
curr_vals: usize,
suffix: S,
usage: U,
color: ColorWhen,
) -> Self
where
A: AnyArg<'a, 'b> + Display,
S: Display,
U: Display,
{
Expand Down Expand Up @@ -792,9 +784,8 @@ impl Error {
}

#[doc(hidden)]
pub fn unexpected_multiple_usage<'a, 'b, A, U>(arg: &A, usage: U, color: ColorWhen) -> Self
pub fn unexpected_multiple_usage<'a, 'b, U>(arg: &AnyArg, usage: U, color: ColorWhen) -> Self
where
A: AnyArg<'a, 'b> + Display,
U: Display,
{
let c = Colorizer::new(ColorizerOption {
Expand Down

0 comments on commit eb8d919

Please sign in to comment.