pub struct FunctionRegistry { /* private fields */ }Expand description
Global registry mapping function names to handlers used during expression evaluation.
Supports both standalone calls and method-style calls on Value receivers.
Implementations§
Source§impl FunctionRegistry
impl FunctionRegistry
Sourcepub fn get_instance() -> &'static RwLock<Self>
pub fn get_instance() -> &'static RwLock<Self>
Get the global singleton instance of the function registry.
This method uses OnceLock to ensure thread-safe one-time initialization
of the function registry with all built-in functions registered.
Uses RwLock to allow multiple concurrent readers while ensuring
exclusive access during writes.
§Returns
Returns a reference to the RwLock-protected singleton function registry.
Sourcepub fn read_lock() -> Result<RwLockReadGuard<'static, Self>>
pub fn read_lock() -> Result<RwLockReadGuard<'static, Self>>
Get a read lock on the function registry for function calls.
This is a convenience method that returns a read guard, allowing multiple concurrent function calls without blocking each other.
§Returns
Returns a Result containing the read guard or an error if the lock is poisoned.
Sourcepub fn write_lock() -> Result<RwLockWriteGuard<'static, Self>>
pub fn write_lock() -> Result<RwLockWriteGuard<'static, Self>>
Get a write lock on the function registry for registration.
This is a convenience method that returns a write guard, providing exclusive access for registering new functions.
§Returns
Returns a Result containing the write guard or an error if the lock is poisoned.
Sourcepub fn register<F>(&mut self, name: Arc<str>, handler: F)where
F: FunctionHandler + 'static,
pub fn register<F>(&mut self, name: Arc<str>, handler: F)where
F: FunctionHandler + 'static,
Register a function handler with the given name.
§Arguments
name- The name to register the function underhandler- The function handler implementation
Sourcepub fn function_call(
&self,
context: &mut dyn ContextLike,
name: Arc<str>,
arg: Arc<Value>,
) -> Result<Arc<Value>>
pub fn function_call( &self, context: &mut dyn ContextLike, name: Arc<str>, arg: Arc<Value>, ) -> Result<Arc<Value>>
Call with a read lock on the global registry. Flattens Array args.
Sourcepub fn method_call(
&self,
context: &mut dyn ContextLike,
name: Arc<str>,
value: Arc<Value>,
arg: Arc<Value>,
) -> Result<Arc<Value>>
pub fn method_call( &self, context: &mut dyn ContextLike, name: Arc<str>, value: Arc<Value>, arg: Arc<Value>, ) -> Result<Arc<Value>>
Call a method handler with value prepended to args. Flattens Array args.
Sourcepub fn handler_exists(&self, name: Arc<str>) -> bool
pub fn handler_exists(&self, name: Arc<str>) -> bool
Returns true if a handler with name is registered.