Skip to main content

FunctionLibrary

Struct FunctionLibrary 

Source
pub struct FunctionLibrary {
    pub host_context_enabled: bool,
    /* private fields */
}
Expand description

Registry of functions available in expressions.

Fields§

§host_context_enabled: bool

Implementations§

Source§

impl FunctionLibrary

Source

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

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

pub fn get_signatures(&self, name: &str) -> &[FunctionEntry]

Get all entries for a function name.

Source

pub fn merge(self, other: FunctionLibrary) -> Self

Merge another library’s registrations into this one.

Source

pub fn function_names(&self) -> impl Iterator<Item = &str>

Get all registered function names.

Source

pub fn call( &self, name: &str, args: &[ExprValue], ctx: &mut dyn EvalContext, ) -> Result<ExprValue, ExpressionError>

Dispatch a function call: exact → coerced → generic.

Source

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).

Source

pub fn derive_return_type( &self, name: &str, arg_types: &[ExprType], ) -> Option<ExprType>

Derive the return type without evaluation (for static type checking). Accepts union types in arg_types and returns a union of all possible return types.

Source

pub fn get_property_type( &self, base_type: &ExprType, property_name: &str, ) -> Option<ExprType>

Get the type of a property access.

Trait Implementations§

Source§

impl Clone for FunctionLibrary

Source§

fn clone(&self) -> FunctionLibrary

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for FunctionLibrary

Source§

fn default() -> FunctionLibrary

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.