Use namespace for ScriptFnDef.

This commit is contained in:
Stephen Chung
2021-03-07 22:10:54 +08:00
parent e87f981674
commit 330d3f87af
12 changed files with 106 additions and 108 deletions

View File

@@ -1,6 +1,6 @@
//! Module defining interfaces to native-Rust functions.
use crate::ast::{FnAccess, ScriptFnDef};
use crate::ast::FnAccess;
use crate::engine::Imports;
use crate::plugin::PluginFunction;
use crate::stdlib::{
@@ -143,6 +143,7 @@ impl<'a> NativeCallContext<'a> {
}
/// Get an iterator over the current set of modules imported via `import` statements.
#[cfg(not(feature = "no_module"))]
#[allow(dead_code)]
#[inline(always)]
pub(crate) fn iter_imports_raw(
&self,
@@ -438,7 +439,7 @@ pub enum CallableFunction {
Plugin(Shared<FnPlugin>),
/// A script-defined function.
#[cfg(not(feature = "no_function"))]
Script(Shared<ScriptFnDef>),
Script(Shared<crate::ast::ScriptFnDef>),
}
impl fmt::Debug for CallableFunction {
@@ -576,7 +577,7 @@ impl CallableFunction {
/// Panics if the [`CallableFunction`] is not [`Script`][CallableFunction::Script].
#[cfg(not(feature = "no_function"))]
#[inline(always)]
pub fn get_fn_def(&self) -> &ScriptFnDef {
pub fn get_fn_def(&self) -> &crate::ast::ScriptFnDef {
match self {
Self::Pure(_) | Self::Method(_) | Self::Iterator(_) | Self::Plugin(_) => {
panic!("function should be scripted")
@@ -642,24 +643,18 @@ impl From<IteratorFn> for CallableFunction {
}
}
impl From<ScriptFnDef> for CallableFunction {
#[cfg(not(feature = "no_function"))]
impl From<crate::ast::ScriptFnDef> for CallableFunction {
#[inline(always)]
fn from(_func: ScriptFnDef) -> Self {
#[cfg(feature = "no_function")]
unreachable!("no_function active");
#[cfg(not(feature = "no_function"))]
fn from(_func: crate::ast::ScriptFnDef) -> Self {
Self::Script(_func.into())
}
}
impl From<Shared<ScriptFnDef>> for CallableFunction {
#[cfg(not(feature = "no_function"))]
impl From<Shared<crate::ast::ScriptFnDef>> for CallableFunction {
#[inline(always)]
fn from(_func: Shared<ScriptFnDef>) -> Self {
#[cfg(feature = "no_function")]
unreachable!("no_function active");
#[cfg(not(feature = "no_function"))]
fn from(_func: Shared<crate::ast::ScriptFnDef>) -> Self {
Self::Script(_func)
}
}