Struct ocaml_interop::OCaml
source · pub struct OCaml<'a, T: 'a> { /* private fields */ }
Expand description
Representation of OCaml values.
Implementations§
source§impl<'a, T> OCaml<'a, T>
impl<'a, T> OCaml<'a, T>
sourcepub fn as_ref<'b>(&'b self) -> OCamlRef<'b, T>where
'a: 'b,
pub fn as_ref<'b>(&'b self) -> OCamlRef<'b, T>where
'a: 'b,
Obtains an OCamlRef
<T>
for this value.
pub fn root(self) -> BoxRoot<T>
sourcepub unsafe fn raw(&self) -> RawOCaml
pub unsafe fn raw(&self) -> RawOCaml
Gets the raw representation for this value reference (pointer or int).
§Safety
The resulting raw pointer will not be tracked, and may become invalid after any call into the OCaml runtime. Great care must be taken when working with these values.
sourcepub fn to_rust<RustT>(&self) -> RustTwhere
RustT: FromOCaml<T>,
pub fn to_rust<RustT>(&self) -> RustTwhere
RustT: FromOCaml<T>,
Converts this OCaml value into a Rust value.
sourcepub unsafe fn custom_ptr_val<U>(&self) -> *const U
pub unsafe fn custom_ptr_val<U>(&self) -> *const U
Meant to match Data_custom_val from mlvalues.h
Experimental
§Safety
Casts to an arbitrary pointer type, take care before dereferencing
Similar to raw(), the resulting pointer can become invalid after any call into the OCaml runtime, for example allocating OCaml values or calling OCaml functions
source§impl<'a, T: 'static> OCaml<'a, DynBox<T>>
impl<'a, T: 'static> OCaml<'a, DynBox<T>>
sourcepub fn box_value(cr: &'a mut OCamlRuntime, v: T) -> Self
pub fn box_value(cr: &'a mut OCamlRuntime, v: T) -> Self
Build an OCaml value wrapping a Rust value
The returned value will be opaque to the OCaml side, though you can provide functions using it and expose them to OCaml.
It will be dropped if it stops being referenced by the GC.
Experimental
source§impl<'a> OCaml<'a, String>
impl<'a> OCaml<'a, String>
sourcepub fn as_bytes(&self) -> &'a [u8] ⓘ
pub fn as_bytes(&self) -> &'a [u8] ⓘ
Returns an [u8]
reference to the internal bytes of this value.
sourcepub fn as_str(&self) -> &'a str
pub fn as_str(&self) -> &'a str
Returns a str
reference to the internal bytes of this value.
§Panics
Panics if the bytes do not form a valid utf8 string.
sourcepub unsafe fn as_str_unchecked(&self) -> &'a str
pub unsafe fn as_str_unchecked(&self) -> &'a str
Returns a str
reference to the internal bytes of this value.
§Safety
No checks are performed to ensure that the returned value is a valid utf8 string.
source§impl<'a> OCaml<'a, OCamlBytes>
impl<'a> OCaml<'a, OCamlBytes>
sourcepub fn as_bytes(&self) -> &'a [u8] ⓘ
pub fn as_bytes(&self) -> &'a [u8] ⓘ
Returns an [u8]
reference to the internal bytes of this value.
sourcepub fn as_str(&self) -> &'a str
pub fn as_str(&self) -> &'a str
Returns a str
reference to the internal bytes of this value.
§Panics
Panics if the bytes do not form a valid utf8 string.
sourcepub unsafe fn as_str_unchecked(&self) -> &'a str
pub unsafe fn as_str_unchecked(&self) -> &'a str
Returns a str
reference to the internal bytes of this value.
§Safety
No checks are performed to ensure that the returned value is a valid utf8 string.
source§impl<'a> OCaml<'a, OCamlInt>
impl<'a> OCaml<'a, OCamlInt>
sourcepub unsafe fn of_i64_unchecked(n: i64) -> OCaml<'static, OCamlInt>
pub unsafe fn of_i64_unchecked(n: i64) -> OCaml<'static, OCamlInt>
Creates an OCaml int from an i64
without checking that it fits in an OCaml fixnum.
§Safety
OCaml ints are represented as 63bits + 1bit tag, so when converting from an i64, a bit of precision is lost.