Expand description
Value wraps the native OCaml value
type
Variants
Root(Root)
Rooted value
Raw(Value)
Reference to a rooted value
NOTE: Value::Raw
should NOT be used to convert arbitrary sys::Value
into Value
Implementations
sourceimpl Value
impl Value
sourcepub unsafe fn alloc(n: usize, tag: Tag) -> Value
pub unsafe fn alloc(n: usize, tag: Tag) -> Value
Allocate a new value with the given size and tag.
sourcepub unsafe fn alloc_tuple(n: usize) -> Value
pub unsafe fn alloc_tuple(n: usize) -> Value
Allocate a new tuple value
sourcepub unsafe fn alloc_small(n: usize, tag: Tag) -> Value
pub unsafe fn alloc_small(n: usize, tag: Tag) -> Value
Allocate a new small value with the given size and tag
sourcepub unsafe fn alloc_final<T>(
finalizer: unsafe extern "C" fn(_: Raw),
cfg: Option<(usize, usize)>
) -> Value
pub unsafe fn alloc_final<T>(
finalizer: unsafe extern "C" fn(_: Raw),
cfg: Option<(usize, usize)>
) -> Value
Allocate a new value with a finalizer
This calls caml_alloc_final
under-the-hood, which can has less than ideal performance
behavior. In most cases you should prefer Pointer::alloc_custom
when possible.
sourcepub unsafe fn alloc_custom<T: Custom>() -> Value
pub unsafe fn alloc_custom<T: Custom>() -> Value
Allocate custom value
sourcepub unsafe fn alloc_abstract_ptr<T>(ptr: *mut T) -> Value
pub unsafe fn alloc_abstract_ptr<T>(ptr: *mut T) -> Value
Allocate an abstract pointer value, it is best to ensure the value is
on the heap using Box::into_raw(Box::from(...))
to create the pointer
and Box::from_raw
to free it
sourcepub unsafe fn new(v: impl Into<Value>) -> Value
pub unsafe fn new(v: impl Into<Value>) -> Value
Create a new Value from an existing OCaml value
sourcepub unsafe fn array_length(&self) -> usize
pub unsafe fn array_length(&self) -> usize
Get array length
sourcepub unsafe fn register_global_root(&mut self)
pub unsafe fn register_global_root(&mut self)
See caml_register_global_root
sourcepub unsafe fn remove_global_root(&mut self)
pub unsafe fn remove_global_root(&mut self)
Set caml_remove_global_root
sourcepub unsafe fn of_str(s: &str) -> Value
pub unsafe fn of_str(s: &str) -> Value
Convert from a pointer to an OCaml string back to an OCaml value
Safety
This function assumes that the str
argument has been allocated by OCaml
sourcepub unsafe fn of_bytes(s: &[u8]) -> Value
pub unsafe fn of_bytes(s: &[u8]) -> Value
Convert from a pointer to an OCaml string back to an OCaml value
Safety
This function assumes that the &[u8]
argument has been allocated by OCaml
sourcepub unsafe fn variant(rt: &Runtime, tag: u8, value: Option<Value>) -> Value
pub unsafe fn variant(rt: &Runtime, tag: u8, value: Option<Value>) -> Value
Create a variant value
sourcepub unsafe fn is_block(&self) -> bool
pub unsafe fn is_block(&self) -> bool
Check if a Value is an integer or block, returning true if the underlying value is a block
sourcepub unsafe fn is_long(&self) -> bool
pub unsafe fn is_long(&self) -> bool
Check if a Value is an integer or block, returning true if the underlying value is an integer
sourcepub unsafe fn store_field<V: IntoValue>(
&mut self,
rt: &Runtime,
i: Size,
val: V
)
pub unsafe fn store_field<V: IntoValue>(
&mut self,
rt: &Runtime,
i: Size,
val: V
)
Set index of underlying OCaml block value
sourcepub unsafe fn nativeint_val(&self) -> isize
pub unsafe fn nativeint_val(&self) -> isize
Convert an OCaml Nativeint
to isize
sourcepub unsafe fn custom_ptr_val<T>(&self) -> *const T
pub unsafe fn custom_ptr_val<T>(&self) -> *const T
Get pointer to data stored in an OCaml custom value
sourcepub unsafe fn custom_ptr_val_mut<T>(&mut self) -> *mut T
pub unsafe fn custom_ptr_val_mut<T>(&mut self) -> *mut T
Get mutable pointer to data stored in an OCaml custom value
sourcepub unsafe fn abstract_ptr_val<T>(&self) -> *const T
pub unsafe fn abstract_ptr_val<T>(&self) -> *const T
Get pointer to the pointer contained by Value
sourcepub unsafe fn abstract_ptr_val_mut<T>(&self) -> *mut T
pub unsafe fn abstract_ptr_val_mut<T>(&self) -> *mut T
Get mutable pointer to the pointer contained by Value
sourcepub unsafe fn string_val(&self) -> &str
pub unsafe fn string_val(&self) -> &str
Get underlying string pointer
sourcepub unsafe fn bytes_val(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub unsafe fn bytes_val(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Get underlying bytes pointer
sourcepub unsafe fn string_val_mut(&mut self) -> &mut str
pub unsafe fn string_val_mut(&mut self) -> &mut str
Get mutable string pointer
sourcepub unsafe fn bytes_val_mut(&mut self) -> &mut [u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub unsafe fn bytes_val_mut(&mut self) -> &mut [u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Get mutable bytes pointer
sourcepub unsafe fn check_result(self) -> Result<Value, Error>
pub unsafe fn check_result(self) -> Result<Value, Error>
Convert value to Rust Result type depending on if the value is an exception or not
sourcepub unsafe fn call<A: IntoValue>(
&self,
rt: &Runtime,
arg1: A
) -> Result<Value, Error>
pub unsafe fn call<A: IntoValue>(
&self,
rt: &Runtime,
arg1: A
) -> Result<Value, Error>
Call a closure with a single argument, returning an exception value
sourcepub unsafe fn call2<A: IntoValue, B: IntoValue>(
&self,
rt: &Runtime,
arg1: A,
arg2: B
) -> Result<Value, Error>
pub unsafe fn call2<A: IntoValue, B: IntoValue>(
&self,
rt: &Runtime,
arg1: A,
arg2: B
) -> Result<Value, Error>
Call a closure with two arguments, returning an exception value
sourcepub unsafe fn call3<A: IntoValue, B: IntoValue, C: IntoValue>(
&self,
rt: &Runtime,
arg1: A,
arg2: B,
arg3: C
) -> Result<Value, Error>
pub unsafe fn call3<A: IntoValue, B: IntoValue, C: IntoValue>(
&self,
rt: &Runtime,
arg1: A,
arg2: B,
arg3: C
) -> Result<Value, Error>
Call a closure with three arguments, returning an exception value
sourcepub unsafe fn call_n<A: AsRef<[Raw]>>(&self, args: A) -> Result<Value, Error>
pub unsafe fn call_n<A: AsRef<[Raw]>>(&self, args: A) -> Result<Value, Error>
Call a closure with n
arguments, returning an exception value
sourcepub unsafe fn modify<V: IntoValue>(&mut self, rt: &Runtime, v: V)
pub unsafe fn modify<V: IntoValue>(&mut self, rt: &Runtime, v: V)
Modify an OCaml value in place
sourcepub unsafe fn modify_raw<V: IntoValue>(&mut self, v: impl Into<Raw>)
pub unsafe fn modify_raw<V: IntoValue>(&mut self, v: impl Into<Raw>)
Modify an OCaml value in place using a raw OCaml value as the new value
sourcepub unsafe fn is_exception_result(&self) -> bool
pub unsafe fn is_exception_result(&self) -> bool
Determines if the current value is an exception
sourcepub unsafe fn hash_variant<S: AsRef<str>>(
rt: &Runtime,
name: S,
a: Option<Value>
) -> Value
pub unsafe fn hash_variant<S: AsRef<str>>(
rt: &Runtime,
name: S,
a: Option<Value>
) -> Value
Get hash variant as OCaml value
sourcepub unsafe fn method<S: AsRef<str>>(
&self,
rt: &Runtime,
name: S
) -> Option<Value>
pub unsafe fn method<S: AsRef<str>>(
&self,
rt: &Runtime,
name: S
) -> Option<Value>
Get object method
sourcepub unsafe fn exception_to_string(&self) -> Result<String, Utf8Error>
pub unsafe fn exception_to_string(&self) -> Result<String, Utf8Error>
Convert an OCaml exception value to the string representation
sourcepub unsafe fn initialize(&mut self, value: Value)
pub unsafe fn initialize(&mut self, value: Value)
Initialize OCaml value using caml_initialize
sourcepub unsafe fn deep_clone_to_ocaml(self) -> Self
pub unsafe fn deep_clone_to_ocaml(self) -> Self
This will recursively clone any OCaml value The new value is allocated inside the OCaml heap, and may end up being moved or garbage collected.
sourcepub unsafe fn deep_clone_to_rust(&self) -> Self
pub unsafe fn deep_clone_to_rust(&self) -> Self
This will recursively clone any OCaml value The new value is allocated outside of the OCaml heap, and should only be used for storage inside Rust structures.
Trait Implementations
sourceimpl<'a, T> FromOCaml<T> for Value
impl<'a, T> FromOCaml<T> for Value
sourcefn from_ocaml(v: OCaml<'_, T>) -> Value
fn from_ocaml(v: OCaml<'_, T>) -> Value
Convert from OCaml value.
sourceimpl<'a> FromValue<'a> for Value
impl<'a> FromValue<'a> for Value
sourcefn from_value(v: Value) -> Value
fn from_value(v: Value) -> Value
Convert from OCaml value
sourceimpl<'a> IntoValue for &Value
impl<'a> IntoValue for &Value
sourcefn into_value(self, _rt: &Runtime) -> Value
fn into_value(self, _rt: &Runtime) -> Value
Convert to OCaml value
sourceimpl IntoValue for Value
impl IntoValue for Value
sourcefn into_value(self, _rt: &Runtime) -> Value
fn into_value(self, _rt: &Runtime) -> Value
Convert to OCaml value
sourceimpl PartialOrd<Value> for Value
impl PartialOrd<Value> for Value
sourcefn partial_cmp(&self, other: &Value) -> Option<Ordering>
fn partial_cmp(&self, other: &Value) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<T> ToOCaml<T> for Value
impl<T> ToOCaml<T> for Value
sourcefn to_boxroot(&self, cr: &mut OCamlRuntime) -> BoxRoot<T>
fn to_boxroot(&self, cr: &mut OCamlRuntime) -> BoxRoot<T>
Convert to OCaml value. Return an already rooted value as BoxRoot
<T>
.
impl StructuralPartialEq for Value
Auto Trait Implementations
impl RefUnwindSafe for Value
impl !Send for Value
impl !Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more