#![cfg(not(feature = "no_function"))]
use super::{FnAccess, StmtBlock};
use crate::{ImmutableString, StaticVec};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{fmt, hash::Hash};
#[cfg(not(feature = "no_module"))]
#[cfg(not(feature = "no_function"))]
#[derive(Debug, Clone)]
pub struct EncapsulatedEnviron {
pub lib: crate::Shared<crate::Module>,
pub imports: Box<[(ImmutableString, crate::Shared<crate::Module>)]>,
pub constants: Option<crate::eval::GlobalConstants>,
}
#[derive(Debug, Clone)]
pub struct ScriptFnDef {
pub body: StmtBlock,
#[cfg(not(feature = "no_module"))]
#[cfg(not(feature = "no_function"))]
pub environ: Option<crate::Shared<EncapsulatedEnviron>>,
pub name: ImmutableString,
pub access: FnAccess,
pub params: StaticVec<ImmutableString>,
#[cfg(feature = "metadata")]
pub comments: Box<[Box<str>]>,
}
impl fmt::Display for ScriptFnDef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}{}({})",
match self.access {
FnAccess::Public => "",
FnAccess::Private => "private ",
},
self.name,
self.params
.iter()
.map(|s| s.as_str())
.collect::<StaticVec<_>>()
.join(", ")
)
}
}
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Hash)]
#[non_exhaustive]
pub struct ScriptFnMetadata<'a> {
pub name: &'a str,
pub params: Vec<&'a str>,
pub access: FnAccess,
#[cfg(feature = "metadata")]
pub comments: Vec<&'a str>,
}
impl fmt::Display for ScriptFnMetadata<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}{}({})",
match self.access {
FnAccess::Public => "",
FnAccess::Private => "private ",
},
self.name,
self.params
.iter()
.copied()
.collect::<StaticVec<_>>()
.join(", ")
)
}
}
impl<'a> From<&'a ScriptFnDef> for ScriptFnMetadata<'a> {
#[inline]
fn from(value: &'a ScriptFnDef) -> Self {
Self {
name: &value.name,
params: value.params.iter().map(|s| s.as_str()).collect(),
access: value.access,
#[cfg(feature = "metadata")]
comments: value.comments.iter().map(<_>::as_ref).collect(),
}
}
}