From a05ce8981c5cc8be4ce94e11e1a953a9b058a671 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Tue, 23 Apr 2024 14:04:47 +0200 Subject: [PATCH] command : plus lisible --- src/command/mod.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/command/mod.rs b/src/command/mod.rs index 1f28de0..3a955a6 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -9,9 +9,6 @@ use crate::variables::Variables; type BuiltinFunction = fn(&Vec, &mut Variables, &mut ExitCode); -#[derive(Debug)] -pub struct NoSuchBuiltinError; - pub trait Command { fn spawn(&mut self, variables: &mut Variables, exit_code: &mut ExitCode); } @@ -22,7 +19,7 @@ pub struct Builtin { } impl Builtin { - pub fn new(argv: &Vec) -> Result { + pub fn new(argv: &Vec) -> Result { let mut args = argv.clone(); let program = args.remove(0); @@ -35,13 +32,9 @@ impl Builtin { _ => None, }; - if function.is_some() { - Ok(Self { - function: function.unwrap(), - args, - }) - } else { - Err(NoSuchBuiltinError) + match function { + Some(function) => Ok(Self { function, args }), + None => Err(()), } } }