rhai/func/plugin.rs
1//! Module defining macros for developing _plugins_.
2
3use super::FnCallArgs;
4pub use super::RhaiFunc;
5pub use crate::{
6 Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, FuncRegistration, ImmutableString,
7 Module, NativeCallContext, Position,
8};
9#[cfg(feature = "no_std")]
10use std::prelude::v1::*;
11pub use std::{any::TypeId, mem};
12
13/// Result of a Rhai function.
14pub type RhaiResult = crate::RhaiResult;
15
16/// Re-export the codegen namespace.
17pub use rhai_codegen::*;
18
19/// Trait implemented by a _plugin function_.
20///
21/// This trait should not be used directly.
22pub trait PluginFunc {
23 /// Call the plugin function with the arguments provided.
24 fn call(&self, context: Option<NativeCallContext>, args: &mut FnCallArgs) -> RhaiResult;
25
26 /// Is this plugin function a method?
27 #[must_use]
28 fn is_method_call(&self) -> bool;
29
30 /// Does this plugin function contain a [`NativeCallContext`] parameter?
31 #[must_use]
32 fn has_context(&self) -> bool;
33
34 /// Is this plugin function pure?
35 ///
36 /// Defaults to `true` such that any old implementation that has constant-checking code inside
37 /// the function itself will continue to work.
38 #[inline(always)]
39 #[must_use]
40 fn is_pure(&self) -> bool {
41 true
42 }
43
44 /// Is this plugin function volatile?
45 ///
46 /// A volatile function is not guaranteed to return the same result for the same input(s).
47 ///
48 /// Defaults to `true` such that any old implementation that has constant-checking code inside
49 /// the function itself will continue to work.
50 #[inline(always)]
51 #[must_use]
52 fn is_volatile(&self) -> bool {
53 true
54 }
55}