pub struct Env<'a> { /* private fields */ }
Expand description
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.
Implementations
sourceimpl<'a> Env<'a>
impl<'a> Env<'a>
sourcepub unsafe fn new<T>(_lifetime_marker: &'a T, env: NIF_ENV) -> Env<'a>
pub unsafe fn new<T>(_lifetime_marker: &'a T, env: NIF_ENV) -> 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).
Unsafe
Don’t create multiple Env
s with the same lifetime.
pub fn as_c_arg(self) -> NIF_ENV
sourcepub fn error_tuple<T>(self, reason: T) -> Term<'a> where
T: Encoder,
pub fn error_tuple<T>(self, reason: T) -> Term<'a> where
T: Encoder,
Convenience method for building a tuple {error, Reason}
.
sourcepub fn send(self, pid: &LocalPid, message: Term<'a>)
pub fn send(self, pid: &LocalPid, message: Term<'a>)
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).
Trait Implementations
sourceimpl<'a, 'b> PartialEq<Env<'b>> 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>
if and only if 'a
and 'b
are the same lifetime.
impl<'a> Copy for Env<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for Env<'a>
impl<'a> !Send for Env<'a>
impl<'a> !Sync for Env<'a>
impl<'a> Unpin for Env<'a>
impl<'a> UnwindSafe for Env<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more