-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
491 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,15 @@ | ||
use std::ops::Deref; | ||
|
||
use crate::{Decoder, Encoder, Env, Error, NifResult, Term, TermType}; | ||
use crate::{Env, Term, TermType}; | ||
|
||
use crate::sys::enif_make_ref; | ||
|
||
wrapper!(Reference, TermType::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>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl<'a> From<Reference<'a>> for Term<'a> { | ||
fn from(term: Reference<'a>) -> Self { | ||
term.0 | ||
} | ||
} | ||
|
||
impl<'a> TryFrom<Term<'a>> for Reference<'a> { | ||
type Error = Error; | ||
|
||
fn try_from(term: Term<'a>) -> Result<Self, Self::Error> { | ||
if term.is_ref() { | ||
Ok(Reference(term)) | ||
} else { | ||
Err(Error::BadArg) | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Decoder<'a> for Reference<'a> { | ||
fn decode(term: Term<'a>) -> NifResult<Self> { | ||
term.try_into() | ||
} | ||
} | ||
|
||
impl Encoder for Reference<'_> { | ||
fn encode<'b>(&self, env: Env<'b>) -> Term<'b> { | ||
self.0.encode(env) | ||
} | ||
wrapper!{ | ||
struct Reference(TermType::Ref) | ||
} | ||
|
||
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()))) } | ||
let term = unsafe { Term::new(self, enif_make_ref(self.as_c_arg())) }; | ||
unsafe { Reference::wrap_unchecked(term) } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.