pub struct ScriptRouter { /* private fields */ }Expand description
Script-based router powered by the rhai scripting engine.
Evaluates routing rules written in rhai script to filter invokers. The script has access to helper functions for querying invoker properties and invocation context, and must return an array of selected invoker indices.
§Script API
| Function | Return | Description |
|---|---|---|
invoker_count() | i64 | Number of invokers |
invoker_ip(i) | String | IP of invoker at index i |
invoker_has_param(i, key) | bool | Check URL param existence |
invoker_get_param(i, key) | String | Get URL param value |
method_name() | String | Current method name |
has_attachment(key) | bool | Check attachment existence |
get_attachment(key) | String | Get attachment value |
The script must return an Array of i64 indices.
Implementations§
Source§impl ScriptRouter
impl ScriptRouter
Sourcepub fn new(script: &str) -> Result<Self, Box<EvalAltResult>>
pub fn new(script: &str) -> Result<Self, Box<EvalAltResult>>
Compile a rhai script and create a new ScriptRouter.
§Errors
Returns rhai::EvalAltResult if the script fails to compile.
pub fn route( &self, invokers: &[Arc<dyn Invoker>], ctx: &InvocationContext, ) -> Vec<usize>
pub fn script(&self) -> &str
Auto Trait Implementations§
impl Freeze for ScriptRouter
impl !RefUnwindSafe for ScriptRouter
impl !Send for ScriptRouter
impl !Sync for ScriptRouter
impl Unpin for ScriptRouter
impl UnsafeUnpin for ScriptRouter
impl !UnwindSafe for ScriptRouter
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
Mutably borrows from an owned value. Read more