[−][src]Struct rustler::env::Env
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.
Methods
impl<'a> Env<'a>
[src]
pub fn pid(self) -> Pid
[src]
Return the calling process's pid.
Panics
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>
[src]
pub unsafe fn new<T>(_lifetime_marker: &'a T, env: NIF_ENV) -> Env<'a>
[src]
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).
Unsafe
Don't create multiple Env
s with the same lifetime.
pub fn as_c_arg(&self) -> NIF_ENV
[src]
pub fn error_tuple<T>(self, reason: T) -> Term<'a> where
T: Encoder,
[src]
T: Encoder,
Convenience method for building a tuple {error, Reason}
.
pub fn send(self, pid: &Pid, message: Term<'a>)
[src]
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
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).
pub fn binary_to_term(self, data: &[u8]) -> Option<(Term<'a>, usize)>
[src]
Decodes binary data to a term.
Follows the erlang External Term Format.
pub unsafe fn binary_to_term_trusted(
self,
data: &[u8]
) -> Option<(Term<'a>, usize)>
[src]
self,
data: &[u8]
) -> Option<(Term<'a>, usize)>
Like binary_to_term
, but can only be called on valid
and trusted data.
Trait Implementations
impl<'a> Copy for Env<'a>
[src]
impl<'a, 'b> PartialEq<Env<'b>> for Env<'a>
[src]
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.
fn eq(&self, other: &Env<'b>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> Clone for Env<'a>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,