From 4df0eca3d40c9496432d34ad44be740eb0a1a5ee Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sun, 29 Mar 2020 19:39:36 -0700 Subject: [PATCH] Remove dependency on crate::Error from arg_defs This change removes the need to import crate::Error from the arg_defs module. By dropping this dependency we make the file more independent of the rest of the crate, which subsequently will allow us to merely include! it in another file in order to get the argument related type definitions without compilation errors due to missing symbols from the rest of the crate. --- src/arg_defs.rs | 7 +++---- src/error.rs | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/arg_defs.rs b/src/arg_defs.rs index 0172a810..c58d230b 100644 --- a/src/arg_defs.rs +++ b/src/arg_defs.rs @@ -19,7 +19,6 @@ use crate::args; use crate::commands; -use crate::error::Error; /// Provides access to a Nitrokey device #[derive(structopt::StructOpt)] @@ -136,13 +135,13 @@ pub enum ConfigOption { } impl ConfigOption { - pub fn try_from(disable: bool, value: Option, name: &'static str) -> Result { + pub fn try_from(disable: bool, value: Option, name: &'static str) -> Result { if disable { if value.is_some() { - Err(Error::Error(format!( + Err(format!( "--{name} and --no-{name} are mutually exclusive", name = name - ))) + )) } else { Ok(ConfigOption::Disable) } diff --git a/src/error.rs b/src/error.rs index 3e458a6f..e891da23 100644 --- a/src/error.rs +++ b/src/error.rs @@ -64,6 +64,12 @@ impl From<&str> for Error { } } +impl From for Error { + fn from(s: String) -> Error { + Error::Error(s) + } +} + impl From for Error { fn from(e: clap::Error) -> Error { Error::ClapError(e)