From 519ae2a261ac283df13ff9859ea97e39de3d3c74 Mon Sep 17 00:00:00 2001 From: Guilhem Date: Wed, 3 Aug 2022 16:29:59 +0200 Subject: [PATCH] refactor: Replace convert_kind to into --- src/cli.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index c2ba11f..3782ab2 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -34,11 +34,19 @@ struct Args { action: Action, } -fn convert_kind(kind_arg: &NotationKindArg) -> NotationKind { - match kind_arg { +impl Into for NotationKindArg { + fn into(self) -> NotationKind { + (&self).into() + } +} + +impl Into for &NotationKindArg { + fn into(self) -> NotationKind { + match self { NotationKindArg::Iso => NotationKind::Iso, NotationKindArg::Uns => NotationKind::Uns, NotationKindArg::Alphanumeric => NotationKind::Alphanumeric, + } } } @@ -47,10 +55,10 @@ pub fn run_cli() { match &args.action { Action::Convert { from, to, value } => { - let tooth_result = Tooth::from(value, &convert_kind(from)); + let tooth_result = Tooth::from(value, &from.into()); let output_string = match tooth_result { - Ok(tooth) => tooth.to(&convert_kind(to)), + Ok(tooth) => tooth.to(&to.into()), Err(err) => err, };