From f80e499e84f0768e3f291148bcf59c023b2f210c Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 14 Mar 2020 23:41:21 +0800 Subject: [PATCH] Minor code cleanup. --- src/builtin.rs | 11 +++++++---- src/fn_register.rs | 11 ++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/builtin.rs b/src/builtin.rs index b69429f4..b85cf306 100644 --- a/src/builtin.rs +++ b/src/builtin.rs @@ -580,7 +580,7 @@ impl Engine<'_> { } fn range(from: T, to: T) -> Range { - (from..to) + from..to } reg_iterator::(self); @@ -773,9 +773,12 @@ impl Engine<'_> { self.register_dynamic_fn("pop", |list: &mut Array| { list.pop().unwrap_or_else(|| ().into_dynamic()) }); - self.register_dynamic_fn("shift", |list: &mut Array| match list.len() { - 0 => ().into_dynamic(), - _ => list.remove(0), + self.register_dynamic_fn("shift", |list: &mut Array| { + if !list.is_empty() { + ().into_dynamic() + } else { + list.remove(0) + } }); self.register_fn("len", |list: &mut Array| list.len() as INT); self.register_fn("clear", |list: &mut Array| list.clear()); diff --git a/src/fn_register.rs b/src/fn_register.rs index 84dbf150..12f15047 100644 --- a/src/fn_register.rs +++ b/src/fn_register.rs @@ -196,13 +196,10 @@ macro_rules! def_register { // Call the user-supplied function using ($clone) to // potentially clone the value, otherwise pass the reference. - match f($(($clone)($par)),*) { - Ok(r) => Ok(Box::new(r) as Dynamic), - Err(mut err) => { - err.set_position(pos); - Err(err) - } - } + f($(($clone)($par)),*).map(|r| Box::new(r) as Dynamic).map_err(|mut err| { + err.set_position(pos); + err + }) }; self.register_fn_raw(name, Some(vec![$(TypeId::of::<$par>()),*]), Box::new(fun)); }