Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with incremental conversion to OCaml values #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/conv/to_ocaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,9 @@ where
})
}
}

unsafe impl<'a, A> ToOCaml<A> for OCaml<'a, A> {
fn to_ocaml(&self, _token: OCamlAllocToken) -> OCamlAllocResult<A> {
OCamlAllocResult::of_ocaml(*self)
}
}
17 changes: 16 additions & 1 deletion src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,27 @@ use ocaml_sys::{caml_string_length, int_val, val_int};
/// Should not be instantiated directly, and will usually be the result
/// of [`ocaml_alloc!`] and [`ocaml_call!`] expressions, or the input arguments
/// of functions defined inside [`ocaml_export!`] blocks.
#[derive(Copy, Clone)]
pub struct OCaml<'a, T: 'a> {
_marker: PhantomData<&'a T>,
raw: RawOCaml,
}

// Trivial, manual implementation because the derive is overly conservative
// and places bounds on type parameter T
// https://github.com/rust-lang/rust/issues/26925
// https://github.com/rust-lang/rust/issues/52079
impl<'a, T: 'a> Clone for OCaml<'a, T> {
fn clone(&self) -> Self {
Self {
_marker: PhantomData,
raw: self.raw,
}
}
}

// As above, avoid unnecessary bounds
impl<'a, T: 'a> Copy for OCaml<'a, T> {}

pub fn make_ocaml<'a, T>(x: RawOCaml) -> OCaml<'a, T> {
OCaml {
_marker: PhantomData,
Expand Down