Struct emacs::Value

source ·
pub struct Value<'e> {
    pub env: &'e Env,
    /* private fields */
}
Expand description

A type that represents Lisp values. Values of this type can be copied around, but are lifetime-bound to the Env they come from.

They are also “proxy values” that are only useful when converted to Rust values, or used as arguments when calling back into the Lisp runtime.

Fields§

§env: &'e Env

Implementations§

source§

impl<'e> Value<'e>

source

pub fn is_not_nil(&self) -> bool

source

pub fn eq(&self, other: Value<'e>) -> bool

source

pub fn into_rust<T: FromLisp<'e>>(self) -> Result<T>

Converts this value into a Rust value of the given type.

source

pub fn into_ref<T: 'static>(self) -> Result<Ref<'e, T>>

source

pub fn into_ref_mut<T: 'static>(self) -> Result<RefMut<'e, T>>

source

pub unsafe fn get_mut<T: Transfer>(&mut self) -> Result<&mut T>

Returns a mutable reference to the underlying Rust data wrapped by this value.

§Safety

There are several ways this can go wrong:

  • Lisp code can pass the same object through 2 different values in an argument list.
  • Rust code earlier in the call chain may have copied this value.
  • Rust code later in the call chain may receive a copy of this value.

In general, it is better to wrap Rust data in RefCell, Mutex, or RwLock guards, before moving them to Lisp, and then only access them through these guards (which can be obtained back through into_rust). This method is for squeezing out the last bit of performance in very rare situations.

source

pub fn car<T: FromLisp<'e>>(self) -> Result<T>

source

pub fn cdr<T: FromLisp<'e>>(self) -> Result<T>

source§

impl<'e> Value<'e>

source

pub fn copy_string_contents(self, buffer: &mut [u8]) -> Result<&[u8]>

Copies the content of this Lisp string value to the given buffer as a null-terminated UTF-8 string. Returns the copied bytes, excluding the null terminator.

Signals an args-out-of-range error if the buffer is too small.

source§

impl<'e> Value<'e>

source

pub fn get_user_ptr(self) -> Result<*mut c_void>

Returns the raw pointer wrapped in this user-ptr object.

In general, prefer the user-ptr supported provided by the defun attr macro. Use this function only for special user-ptr types, such as newtypes wrapping opaque pointers.

source

pub fn get_user_finalizer(self) -> Result<emacs_finalizer_function>

Returns the finalizer function associated with this user-ptr object.

In general, prefer the user-ptr supported provided by the defun attr macro. Use this function only for special user-ptr types, such as newtypes wrapping opaque pointers.

source§

impl<'e> Value<'e>

source

pub fn call<A>(self, args: A) -> Result<Value<'e>>
where A: IntoLispArgs<'e>,

Calls this 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.

§Examples
#[defun]
fn mapc_enumerate_vec(function: Value, vector: Vector) -> Result<()> {
    for (nth, elem) in vector.into_iter().enumerate() {
        function.call((nth, elem))?;
    }
    Ok(())
}
source

pub unsafe fn call_unprotected<A>(self, args: A) -> Result<Value<'e>>
where A: IntoLispArgs<'e>,

Like call, except that the returned Value is not protected against Emacs GC’s bug #31238, which caused issue #2.

§Safety

This can be used as an optimization, in situations when the returned Value is unused, or when its usage is shorter than the lifespan of the underlying Lisp object.

source§

impl<'e> Value<'e>

source

pub fn make_global_ref(self) -> GlobalRef

Creates a new GlobalRef for this value.

Trait Implementations§

source§

impl<'e> Clone for Value<'e>

source§

fn clone(&self) -> Value<'e>

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

impl<'e> Debug for Value<'e>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'e> FromLisp<'e> for Value<'e>

source§

fn from_lisp(value: Value<'e>) -> Result<Value<'_>>

source§

impl<'e> IntoLisp<'e> for Value<'e>

source§

fn into_lisp(self, _: &'e Env) -> Result<Value<'_>>

source§

impl<'e> Copy for Value<'e>

Auto Trait Implementations§

§

impl<'e> Freeze for Value<'e>

§

impl<'e> !RefUnwindSafe for Value<'e>

§

impl<'e> !Send for Value<'e>

§

impl<'e> !Sync for Value<'e>

§

impl<'e> Unpin for Value<'e>

§

impl<'e> !UnwindSafe for Value<'e>

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> 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,

§

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>,

§

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>,

§

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.