casbin::rhai

Struct FuncRegistration

pub struct FuncRegistration { /* private fields */ }
Expand description

Type for fine-tuned module function registration.

Implementations§

§

impl FuncRegistration

pub fn new(name: impl Into<SmartString<LazyCompact>>) -> FuncRegistration

Create a new FuncRegistration.

§Defaults
  • Accessibility: The function namespace is FnNamespace::Internal.

  • Purity: The function is assumed to be pure unless it is a property setter or an index setter.

  • Volatility: The function is assumed to be non-volatile – i.e. it guarantees the same result for the same input(s).

  • Metadata: No metadata for the function is registered.

let mut module = Module::new();

fn inc(x: i64) -> i64 { x + 1 }

let f = FuncRegistration::new("inc")
    .in_global_namespace()
    .set_into_module(&mut module, inc);

let hash = f.hash;

assert!(module.contains_fn(hash));

pub fn new_getter(prop: impl AsRef<str>) -> FuncRegistration

Create a new FuncRegistration for a property getter.

Not available under no_object.

§Defaults
  • Accessibility: The function namespace is FnNamespace::Global.

  • Purity: The function is assumed to be pure.

  • Volatility: The function is assumed to be non-volatile – i.e. it guarantees the same result for the same input(s).

  • Metadata: No metadata for the function is registered.

pub fn new_setter(prop: impl AsRef<str>) -> FuncRegistration

Create a new FuncRegistration for a property setter.

Not available under no_object.

§Defaults
  • Accessibility: The function namespace is FnNamespace::Global.

  • Purity: The function is assumed to be no-pure.

  • Volatility: The function is assumed to be non-volatile – i.e. it guarantees the same result for the same input(s).

  • Metadata: No metadata for the function is registered.

pub fn new_index_getter() -> FuncRegistration

Create a new FuncRegistration for an index getter.

Not available under both no_index and no_object.

§Defaults
  • Accessibility: The function namespace is FnNamespace::Global.

  • Purity: The function is assumed to be pure.

  • Volatility: The function is assumed to be non-volatile – i.e. it guarantees the same result for the same input(s).

  • Metadata: No metadata for the function is registered.

pub fn new_index_setter() -> FuncRegistration

Create a new FuncRegistration for an index setter.

Not available under both no_index and no_object.

§Defaults
  • Accessibility: The function namespace is FnNamespace::Global.

  • Purity: The function is assumed to be no-pure.

  • Volatility: The function is assumed to be non-volatile – i.e. it guarantees the same result for the same input(s).

  • Metadata: No metadata for the function is registered.

pub const fn with_namespace(self, namespace: FnNamespace) -> FuncRegistration

Set the namespace of the function.

pub const fn in_global_namespace(self) -> FuncRegistration

Set the function to the global namespace.

pub const fn in_internal_namespace(self) -> FuncRegistration

Set the function to the internal namespace.

pub const fn with_purity(self, pure: bool) -> FuncRegistration

Set whether the function is pure. A pure function has no side effects.

pub const fn with_volatility(self, volatile: bool) -> FuncRegistration

Set whether the function is volatile. A volatile function does not guarantee the same result for the same input(s).

pub fn register_into_engine<A, const N: usize, const X: bool, R, const F: bool, FUNC>( self, engine: &mut Engine, func: FUNC, ) -> &FuncMetadata
where A: 'static, R: Variant + Clone, FUNC: RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static,

Register the function into the specified Engine.

pub fn set_into_module<A, const N: usize, const X: bool, R, const F: bool, FUNC>( self, module: &mut Module, func: FUNC, ) -> &FuncMetadata
where A: 'static, R: Variant + Clone, FUNC: RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static,

Register the function into the specified Module.

pub fn set_into_module_raw( self, module: &mut Module, arg_types: impl AsRef<[TypeId]>, func: RhaiFunc, ) -> &FuncMetadata

Register the function into the specified Module.

§WARNING - Low Level API

This function is very low level. It takes a list of TypeId’s indicating the actual types of the parameters.

§Panics

Panics if the type of the first parameter is Array, Map, String, ImmutableString, &str or INT and the function name indicates that it is an index getter or setter.

Indexers for arrays, object maps, strings and integers cannot be registered.

Trait Implementations§

§

impl Clone for FuncRegistration

§

fn clone(&self) -> FuncRegistration

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for FuncRegistration

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Hash for FuncRegistration

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for FuncRegistration

§

fn eq(&self, other: &FuncRegistration) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Eq for FuncRegistration

§

impl StructuralPartialEq for FuncRegistration

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, dst: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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.
Source§

impl<T> EventKey for T
where T: Hash + PartialEq + Eq + Send + Sync,