casbin::rhai

Struct EvalContext

pub struct EvalContext<'a, 's, 'ps, 'g, 'c, 't> { /* private fields */ }
Expand description

Context of a script evaluation process.

Implementations§

§

impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't>

pub const fn engine(&self) -> &'a Engine

The current Engine.

pub fn source(&self) -> Option<&str>

The current source.

pub const fn scope(&self) -> &Scope<'ps>

The current Scope.

pub fn scope_mut(&mut self) -> &mut Scope<'ps>

Get a mutable reference to the current Scope.

pub const fn tag(&self) -> &Dynamic

Custom state kept in a Dynamic.

pub fn tag_mut(&mut self) -> &mut Dynamic

Mutable reference to the custom state kept in a Dynamic.

pub fn this_ptr(&self) -> Option<&Dynamic>

The current bound this pointer, if any.

pub fn this_ptr_mut(&mut self) -> Option<&mut Dynamic>

Mutable reference to the current bound this pointer, if any.

pub const fn call_level(&self) -> usize

The current nesting level of function calls.

pub fn eval_expression_tree( &mut self, expr: &Expression<'_>, ) -> Result<Dynamic, Box<EvalAltResult>>

Evaluate an expression tree within this evaluation context.

§WARNING - Low Level API

This function is very low level. It evaluates an expression from an AST.

pub fn eval_expression_tree_raw( &mut self, expr: &Expression<'_>, rewind_scope: bool, ) -> Result<Dynamic, Box<EvalAltResult>>

👎Deprecated: This API is NOT deprecated, but it is considered volatile and may change in the future.

Evaluate an expression tree within this evaluation context.

The following option is available:

  • whether to rewind the Scope after evaluation if the expression is a [StmtBlock][crate::ast::StmtBlock]
§WARNING - Unstable API

This API is volatile and may change in the future.

§WARNING - Low Level API

This function is extremely low level. It evaluates an expression from an AST.

pub fn call_fn<T>( &mut self, fn_name: impl AsRef<str>, args: impl FuncArgs, ) -> Result<T, Box<EvalAltResult>>
where T: Variant + Clone,

Call a function inside the evaluation context with the provided arguments.

pub fn call_native_fn<T>( &mut self, fn_name: impl AsRef<str>, args: impl FuncArgs, ) -> Result<T, Box<EvalAltResult>>
where T: Variant + Clone,

Call a registered native Rust function inside the evaluation context with the provided arguments.

This is often useful because Rust functions typically only want to cross-call other registered Rust functions and not have to worry about scripted functions hijacking the process unknowingly (or deliberately).

pub fn call_fn_raw( &mut self, fn_name: impl AsRef<str>, is_ref_mut: bool, is_method_call: bool, args: &mut [&mut Dynamic], ) -> Result<Dynamic, Box<EvalAltResult>>

Call a function (native Rust or scripted) inside the evaluation context.

If is_method_call is true, the first argument is assumed to be the this pointer for a script-defined function (or the object of a method call).

§WARNING - Low Level API

This function is very low level.

§Arguments

All arguments may be consumed, meaning that they may be replaced by (). This is to avoid unnecessarily cloning the arguments.

DO NOT reuse the arguments after this call. If they are needed afterwards, clone them before calling this function.

If is_ref_mut is true, the first argument is assumed to be passed by reference and is not consumed.

pub fn call_native_fn_raw( &mut self, fn_name: impl AsRef<str>, is_ref_mut: bool, args: &mut [&mut Dynamic], ) -> Result<Dynamic, Box<EvalAltResult>>

Call a registered native Rust function inside the evaluation context.

This is often useful because Rust functions typically only want to cross-call other registered Rust functions and not have to worry about scripted functions hijacking the process unknowingly (or deliberately).

§WARNING - Low Level API

This function is very low level.

§Arguments

All arguments may be consumed, meaning that they may be replaced by (). This is to avoid unnecessarily cloning the arguments.

DO NOT reuse the arguments after this call. If they are needed afterwards, clone them before calling this function.

If is_ref_mut is true, the first argument is assumed to be passed by reference and is not consumed.

Auto Trait Implementations§

§

impl<'a, 's, 'ps, 'g, 'c, 't> Freeze for EvalContext<'a, 's, 'ps, 'g, 'c, 't>

§

impl<'a, 's, 'ps, 'g, 'c, 't> !RefUnwindSafe for EvalContext<'a, 's, 'ps, 'g, 'c, 't>

§

impl<'a, 's, 'ps, 'g, 'c, 't> Send for EvalContext<'a, 's, 'ps, 'g, 'c, 't>

§

impl<'a, 's, 'ps, 'g, 'c, 't> Sync for EvalContext<'a, 's, 'ps, 'g, 'c, 't>

§

impl<'a, 's, 'ps, 'g, 'c, 't> Unpin for EvalContext<'a, 's, 'ps, 'g, 'c, 't>

§

impl<'a, 's, 'ps, 'g, 'c, 't> !UnwindSafe for EvalContext<'a, 's, 'ps, 'g, 'c, 't>

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