ocaml-rs icon indicating copy to clipboard operation
ocaml-rs copied to clipboard

custom! with bounds

Open mimoo opened this issue 3 years ago • 5 comments

I'm trying to use the custom! macro on a generic struct with bounds:

ocaml::custom!(CamlRandomOracles<F> where F: Field  {
    finalize: CamlRandomOracles::caml_pointer_finalize
});

but it seems like custom! is unhappy. Is there a way to do this with custom!? Will I have to implement Custom manually?

mimoo avatar Jun 22 '21 20:06 mimoo

It looks like it might possible like this:

 impl<F> ocaml::Custom for CamlRandomOracles<F> where F: Field{
            ocaml::custom! CamlRandomOracles<F> {
                name: concat!("CamlRandomOracles"),
                finalize: CamlRandomOracles::caml_pointer_finalize,
            }
        }

The problem is that the name is going to be the same no matter the type F used right?

mimoo avatar Jun 22 '21 20:06 mimoo

Hm, the custom API is next on my list for some cleanup. I will keep this in mind when figuring about what to do with it.

zshipko avatar Jun 23 '21 00:06 zshipko

btw when would you choose a custom type over creating ocaml types for everything?

mimoo avatar Jun 30 '21 21:06 mimoo

@mimoo I use custom types to wrap pointers to Rust values that I pass around and use from OCaml. When calling Rust functions, OCaml passes these fat pointers back to Rust as arguments to those functions. These are values that have no meaningful conversion to an OCaml (in the case of my example, these are handles to access a database).

tizoc avatar Jun 30 '21 21:06 tizoc

I see, that makes sense!

mimoo avatar Jul 01 '21 01:07 mimoo