[−][src]Trait ocaml::custom::Custom
Custom
is used to define OCaml types that wrap existing Rust types, but are owned by the
garbage collector
A custom type can only be converted to a Value
using ToValue
, but can't be converted from a
value. Once the Rust value is owned by OCaml it should be accessed using ocaml::Pointer
to
avoid reallocating the same value
struct Example(ocaml::Int); ocaml::custom! (Example); #[cfg(feature = "derive")] #[ocaml::func] pub unsafe fn example() -> Example { Example(123) } #[cfg(feature = "derive")] #[ocaml::func] pub unsafe fn example_value(x: ocaml::Pointer<Example>) -> ocaml::Int { x.as_ref().0 }
Associated Constants
const NAME: &'static str
Custom type name
const FIXED_LENGTH: Option<custom_fixed_length>
Custom type fixed length
const OPS: CustomOps
Custom operations
const USED: usize
used
parameter to alloc_custom
. This helps determine the frequency of garbage
collection related to this custom type.
const MAX: usize
max
parameter to alloc_custom
. This helps determine the frequency of garbage collection
related to this custom type