ocaml-rs
ocaml-rs copied to clipboard
custom! with bounds
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?
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?
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.
btw when would you choose a custom type over creating ocaml types for everything?
@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).
I see, that makes sense!