Struct rustler::env::Env[][src]

pub struct Env<'a> { /* fields omitted */ }

On each NIF call, a Env is passed in. The Env is used for most operations that involve communicating with the BEAM, like decoding and encoding terms.

There is no way to allocate a Env at the moment, but this may be possible in the future.


impl<'a> Env<'a>

Return the calling process's pid.


Panics if this environment is process-independent. (The only way to get such an environment is to use OwnedEnv. The Env that Rustler passes to NIFs when they're called is always associated with the calling Erlang process.)

impl<'a> Env<'a>

Create a new Env. For the _lifetime_marker argument, pass a reference to any local variable that has its own lifetime, different from all other Env values. The purpose of the argument is to make it easier to know for sure that the Env you're creating has a unique lifetime (i.e. that you're following the most important safety rule of Rustler).


Don't create multiple Envs with the same lifetime.

Convenience method for building a tuple {error, Reason}.

Send a message to a process.

The Erlang VM imposes some odd restrictions on sending messages. You can send messages in either of these situations:

  • The current thread is managed by the Erlang VM, and self is the environment of the calling process (that is, the environment that Rustler passed in to your NIF); or

  • The current thread is not managed by the Erlang VM.


Panics if the above rules are broken (by trying to send a message from an OwnedEnv on a thread that's managed by the Erlang VM).

Decodes binary data to a term.

Follows the erlang External Term Format.

Like binary_to_term, but can only be called on valid and trusted data.

Trait Implementations

impl<'a> Clone for Env<'a>

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> Copy for Env<'a>

impl<'a, 'b> PartialEq<Env<'b>> for Env<'a>

Two environments are equal if they're the same NIF_ENV value.

A Env<'a> is equal to a Env<'b> iff 'a and 'b are the same lifetime.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

impl<'a> !Send for Env<'a>

impl<'a> !Sync for Env<'a>