pub trait Transfer: Sized + 'static {
// Provided method
fn type_name() -> &'static str { ... }
}
Expand description
Allowing a type to be exposed to Lisp, where its values appear as opaque objects, or “embedded
user pointers” (printed as #<user-ptr ...>
).
When a (boxed) value of this type is transferred to Lisp, the GC becomes its owner. Afterwards, module code can only access it through immutable references.
The ’static bound disallows transferring short-lived references, which can become invalid while still being held by the Lisp runtime.
This works, because the returned string is copied into the Lisp runtime.
use emacs::{defun, Result};
#[defun]
fn foo(s: &String) -> Result<&str> {
Ok(s)
}
This doesn’t work, because the function attempts to give the Lisp runtime a temporary reference.
use emacs::{defun, Result};
#[defun(user_ptr)]
fn foo(s: &String) -> Result<&str> {
Ok(s)
}
Provided Methods§
sourcefn type_name() -> &'static str
fn type_name() -> &'static str
Returns the name of this type. This is used to report runtime type errors, when a function
expects values of this type, but receives values of a different type instead. The default
implementation defers to the type_name
function in std::any
, which can be overridden
for better error reporting.