Skip to content

Commit

Permalink
Add comments and in_env variant returning a ref again
Browse files Browse the repository at this point in the history
  • Loading branch information
filmor committed Oct 13, 2024
1 parent 6256b36 commit 394fc44
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rustler/src/types/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ use crate::{Decoder, Encoder, Env, Error, NifResult, Term};

use crate::sys::enif_make_ref;

/// Wrapper for BEAM reference terms.
#[derive(PartialEq, Eq, Clone, Copy)]
pub struct Reference<'a>(Term<'a>);

impl<'a> Reference<'a> {
/// Returns a representation of self in the given Env.
///
/// If the term is already is in the provided env, it will be directly returned. Otherwise
/// the term will be copied over.
pub fn in_env<'b>(&self, env: Env<'b>) -> Reference<'b> {
Reference(self.0.in_env(env))
}
}

impl<'a> Deref for Reference<'a> {
type Target = Term<'a>;

Expand Down Expand Up @@ -46,6 +57,7 @@ impl<'a> Encoder for Reference<'a> {
}

impl<'a> Env<'a> {
/// Create a new reference in this environment
pub fn make_ref(self) -> Reference<'a> {
unsafe { Reference(Term::new(self, enif_make_ref(self.as_c_arg()))) }
}
Expand Down

0 comments on commit 394fc44

Please sign in to comment.