Remove Box on callback traits.

This commit is contained in:
Stephen Chung
2022-01-27 23:55:32 +08:00
parent 64de20bcd3
commit e476929597
7 changed files with 66 additions and 53 deletions

View File

@@ -17,7 +17,7 @@ pub enum CallableFunction {
/// and the rest passed by value.
Method(Shared<FnAny>),
/// An iterator function.
Iterator(IteratorFn),
Iterator(Shared<IteratorFn>),
/// A plugin function,
Plugin(Shared<FnPlugin>),
/// A script-defined function.
@@ -177,9 +177,9 @@ impl CallableFunction {
/// Get a reference to an iterator function.
#[inline]
#[must_use]
pub fn get_iter_fn(&self) -> Option<IteratorFn> {
pub fn get_iter_fn(&self) -> Option<&IteratorFn> {
match self {
Self::Iterator(f) => Some(*f),
Self::Iterator(f) => Some(f.as_ref()),
Self::Pure(_) | Self::Method(_) | Self::Plugin(_) => None,
#[cfg(not(feature = "no_function"))]
@@ -218,13 +218,6 @@ impl CallableFunction {
}
}
impl From<IteratorFn> for CallableFunction {
#[inline(always)]
fn from(func: IteratorFn) -> Self {
Self::Iterator(func)
}
}
#[cfg(not(feature = "no_function"))]
impl From<crate::ast::ScriptFnDef> for CallableFunction {
#[inline(always)]