pub struct GlobalRef { /* private fields */ }
Expand description
A “global reference” that can live outside the scope of an Env
. This is useful for sharing
an otherwise short-lived Lisp Value
across multiple invocations of Rust functions defined
with defun
. Examples include efficient access to interned symbols or Lisp functions, and
Rust-based multi-threading.
§Implementation
Cloning this struct requires an Env
, so it doesn’t implement Clone
.
free_global_ref
requires an Env
. Therefore, to avoid leaking the underlying Value
,
free
should be used to free a global reference, instead of drop
. For the use case of
accessing interned symbols and Lisp functions, this is a non-issue, as the values are
supposed to be “static” anyway.
The above is a shortcoming in the design of emacs-module. There are 2 possible ways to fix it:
- Make
free_global_ref
work without an env, like Erlang’senif_release_resource
. - Allow
user_ptr
’s finalizer to access the env, to properly free associated global refs.
Implementations§
source§impl GlobalRef
impl GlobalRef
sourcepub fn call<'e, A>(&'e self, env: &'e Env, args: A) -> Result<Value<'_>>where
A: IntoLispArgs<'e>,
pub fn call<'e, A>(&'e self, env: &'e Env, args: A) -> Result<Value<'_>>where
A: IntoLispArgs<'e>,
Calls this reference’s value with the given arguments. An error is signaled if it is actually not a Lisp’s callable.
args
should be an array/slice of Value
, or a tuple of different types, each implementing
IntoLisp
.