Trait emacs::Transfer

source ·
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§

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T: 'static> Transfer for Rc<T>

source§

impl<T: 'static> Transfer for Arc<T>

source§

impl<T: 'static> Transfer for RefCell<T>

source§

impl<T: 'static> Transfer for Mutex<T>

source§

impl<T: 'static> Transfer for RwLock<T>

Implementors§