Minor code cleanup.

This commit is contained in:
Stephen Chung 2020-03-14 23:41:21 +08:00
parent 01cf777961
commit f80e499e84
2 changed files with 11 additions and 11 deletions

View File

@ -580,7 +580,7 @@ impl Engine<'_> {
}
fn range<T>(from: T, to: T) -> Range<T> {
(from..to)
from..to
}
reg_iterator::<INT>(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());

View File

@ -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));
}