pub struct FunctionLibrary {
pub host_context_enabled: bool,
/* private fields */
}Expand description
Registry of functions available in expressions.
Fields§
§host_context_enabled: boolImplementations§
Source§impl FunctionLibrary
impl FunctionLibrary
Sourcepub fn for_profile(profile: &ExprProfile) -> Arc<FunctionLibrary> ⓘ
pub fn for_profile(profile: &ExprProfile) -> Arc<FunctionLibrary> ⓘ
Construct or retrieve a cached function library matching the given expression profile.
Libraries are cached keyed on the profile’s
(revision, extensions, host-kind) triple. Profiles that differ
only in the specific Arc<Vec<PathMappingRule>> they carry share
a cached skeleton; the rules are applied as a cheap clone-and-
register on top for each call.
§Examples
use openjd_expr::{ExprProfile, FunctionLibrary, HostContext};
// Default library for template validation — host functions available
// as unresolved type-check stubs.
let profile = ExprProfile::current().with_host_context(HostContext::Unresolved);
let lib = FunctionLibrary::for_profile(&profile);
assert!(lib.host_context_enabled);
// Runtime library with real path mapping rules.
let profile = ExprProfile::current()
.with_host_context(HostContext::with_rules(Vec::new()));
let lib = FunctionLibrary::for_profile(&profile);
assert!(lib.host_context_enabled);Source§impl FunctionLibrary
impl FunctionLibrary
pub fn new() -> Self
Sourcepub fn register<F>(
&mut self,
name: &str,
signature: ExprType,
implementation: F,
)where
F: Fn(&mut dyn EvalContext, &[ExprValue]) -> Result<ExprValue, ExpressionError> + Send + Sync + 'static,
pub fn register<F>(
&mut self,
name: &str,
signature: ExprType,
implementation: F,
)where
F: Fn(&mut dyn EvalContext, &[ExprValue]) -> Result<ExprValue, ExpressionError> + Send + Sync + 'static,
Register a function overload with an ExprType::Signature.
Accepts either a bare fn pointer or a closure — anything implementing
Fn(&mut dyn EvalContext, &[ExprValue]) -> Result<ExprValue, ExpressionError>
with Send + Sync + 'static. Closures enable wrapping host state
(e.g., AWS clients, config) without plumbing it through EvalContext.
Sourcepub fn register_sig<F>(
&mut self,
name: &str,
sig_str: &str,
implementation: F,
) -> Result<(), String>where
F: Fn(&mut dyn EvalContext, &[ExprValue]) -> Result<ExprValue, ExpressionError> + Send + Sync + 'static,
pub fn register_sig<F>(
&mut self,
name: &str,
sig_str: &str,
implementation: F,
) -> Result<(), String>where
F: Fn(&mut dyn EvalContext, &[ExprValue]) -> Result<ExprValue, ExpressionError> + Send + Sync + 'static,
Register from spec notation: lib.register_sig("len", "(list[T1]) -> int", len_list)
Returns Err if sig_str cannot be parsed as a valid type
signature. The function is not registered on failure.
Sourcepub fn get_signatures(&self, name: &str) -> &[FunctionEntry]
pub fn get_signatures(&self, name: &str) -> &[FunctionEntry]
Get all entries for a function name.
Sourcepub fn merge(self, other: FunctionLibrary) -> Self
pub fn merge(self, other: FunctionLibrary) -> Self
Merge another library’s registrations into this one.
Sourcepub fn function_names(&self) -> impl Iterator<Item = &str>
pub fn function_names(&self) -> impl Iterator<Item = &str>
Get all registered function names.
Sourcepub fn call(
&self,
name: &str,
args: &[ExprValue],
ctx: &mut dyn EvalContext,
) -> Result<ExprValue, ExpressionError>
pub fn call( &self, name: &str, args: &[ExprValue], ctx: &mut dyn EvalContext, ) -> Result<ExprValue, ExpressionError>
Dispatch a function call: exact → coerced → generic.
Sourcepub fn call_method(
&self,
name: &str,
args: &[ExprValue],
ctx: &mut dyn EvalContext,
) -> Result<ExprValue, ExpressionError>
pub fn call_method( &self, name: &str, args: &[ExprValue], ctx: &mut dyn EvalContext, ) -> Result<ExprValue, ExpressionError>
Dispatch a method call (skip receiver coercion on first arg).
Trait Implementations§
Source§impl Clone for FunctionLibrary
impl Clone for FunctionLibrary
Source§fn clone(&self) -> FunctionLibrary
fn clone(&self) -> FunctionLibrary
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for FunctionLibrary
impl Default for FunctionLibrary
Source§fn default() -> FunctionLibrary
fn default() -> FunctionLibrary
Auto Trait Implementations§
impl Freeze for FunctionLibrary
impl !RefUnwindSafe for FunctionLibrary
impl Send for FunctionLibrary
impl Sync for FunctionLibrary
impl Unpin for FunctionLibrary
impl UnsafeUnpin for FunctionLibrary
impl !UnwindSafe for FunctionLibrary
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more