Value

Enum Value 

Source
pub enum Value {
    Root(Root),
    Raw(Value),
}
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§

Source§

impl Value

Source

pub fn raw(&self) -> Raw

Get raw OCaml value

Source

pub fn to<T: FromValue>(&self) -> T

Helper function to convert from Value to T

Source

pub fn into<T: FromValue>(self) -> T

Helper function to convert from Value to T

Source

pub unsafe fn named(name: &str) -> Option<Value>

Returns a named value registered by OCaml

Source

pub unsafe fn alloc(n: usize, tag: Tag) -> Value

Allocate a new value with the given size and tag.

Source

pub unsafe fn alloc_double_array(n: usize) -> Value

Allocate a new float array

Source

pub unsafe fn alloc_tuple(n: usize) -> Value

Allocate a new tuple value

Source

pub unsafe fn alloc_small(n: usize, tag: Tag) -> Value

Allocate a new small value with the given size and tag

Source

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.

Source

pub unsafe fn alloc_custom<T: Custom>() -> Value

Allocate custom value

Source

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

Source

pub unsafe fn new<T: Into<Value>>(v: T) -> Value

Create a new Value from an existing OCaml value

Source

pub unsafe fn array_length(&self) -> usize

Get array length

Source

pub unsafe fn register_global_root(&mut self)

See caml_register_global_root

Source

pub unsafe fn remove_global_root(&mut self)

Set caml_remove_global_root

Source

pub unsafe fn tag(&self) -> Tag

Get the tag for the underlying OCaml value

Source

pub unsafe fn bool(b: bool) -> Value

Convert a boolean to OCaml value

Source

pub unsafe fn string<S: AsRef<str>>(s: S) -> Value

Allocate and copy a string value

Source

pub unsafe fn bytes<S: AsRef<[u8]>>(s: S) -> Value

Allocate and copy a byte array value

Source

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

Source

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

Source

pub unsafe fn some<V: ToValue>(rt: &Runtime, v: V) -> Value

OCaml Some value

Source

pub fn none() -> Value

OCaml None value

Source

pub fn unit() -> Value

OCaml Unit value

Source

pub unsafe fn variant(rt: &Runtime, tag: u8, value: Option<Value>) -> Value

Create a variant value

Source

pub unsafe fn result_ok<T: ToValue>(rt: &Runtime, value: T) -> Value

Result.Ok value

Source

pub unsafe fn result<A: FromValue, B: FromValue>(&self) -> Result<A, B>

Convert OCaml ('a, 'b) Result.t to Rust Result<Value, Value>

Source

pub unsafe fn result_error<T: ToValue>(rt: &Runtime, value: T) -> Value

Result.Error value

Source

pub unsafe fn int(i: Int) -> Value

Create an OCaml int

Source

pub unsafe fn uint(i: Uint) -> Value

Create an OCaml int

Source

pub unsafe fn int64(i: i64) -> Value

Create an OCaml Int64 from i64

Source

pub unsafe fn int32(i: i32) -> Value

Create an OCaml Int32 from i32

Source

pub unsafe fn nativeint(i: isize) -> Value

Create an OCaml Nativeint from isize

Source

pub unsafe fn double(d: f64) -> Value

Create an OCaml Float from f64

Source

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

Source

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

Source

pub unsafe fn field(&self, i: Size) -> Value

Get index of underlying OCaml block value

Source

pub unsafe fn double_field(&self, i: Size) -> f64

Get index of underlying OCaml double array value

Source

pub unsafe fn store_field<V: ToValue>(&mut self, rt: &Runtime, i: Size, val: V)

Set index of underlying OCaml block value

Source

pub unsafe fn store_double_field(&mut self, i: Size, val: f64)

Set index of underlying OCaml double array value

Source

pub unsafe fn int_val(&self) -> isize

Convert an OCaml int to isize

Source

pub unsafe fn double_val(&self) -> f64

Convert an OCaml Float to f64

Source

pub unsafe fn store_double_val(&mut self, val: f64)

Store f64 in OCaml Float

Source

pub unsafe fn int32_val(&self) -> i32

Convert an OCaml Int32 to i32

Source

pub unsafe fn int64_val(&self) -> i64

Convert an OCaml Int64 to i64

Source

pub unsafe fn nativeint_val(&self) -> isize

Convert an OCaml Nativeint to isize

Source

pub unsafe fn custom_ptr_val<T>(&self) -> *const T

Get pointer to data stored in an OCaml custom value

Source

pub unsafe fn custom_ptr_val_mut<T>(&mut self) -> *mut T

Get mutable pointer to data stored in an OCaml custom value

Source

pub unsafe fn abstract_ptr_val<T>(&self) -> *const T

Get pointer to the pointer contained by Value

Source

pub unsafe fn abstract_ptr_val_mut<T>(&self) -> *mut T

Get mutable pointer to the pointer contained by Value

Source

pub unsafe fn string_val(&self) -> &str

Get underlying string pointer

Source

pub unsafe fn bytes_val(&self) -> &[u8]

Get underlying bytes pointer

Source

pub unsafe fn string_val_mut(&mut self) -> &mut str

Get mutable string pointer

Source

pub unsafe fn bytes_val_mut(&mut self) -> &mut [u8]

Get mutable bytes pointer

Source

pub unsafe fn exception(&self) -> Option<Value>

Extract OCaml exception

Source

pub unsafe fn call1<A: ToValue>( &self, rt: &Runtime, arg1: A, ) -> Result<Value, Error>

Call a closure with a single argument, returning an exception result

Source

pub unsafe fn call2<A: ToValue, B: ToValue>( &self, rt: &Runtime, arg1: A, arg2: B, ) -> Result<Value, Error>

Call a closure with two arguments, returning an exception result

Source

pub unsafe fn call3<A: ToValue, B: ToValue, C: ToValue>( &self, rt: &Runtime, arg1: A, arg2: B, arg3: C, ) -> Result<Value, Error>

Call a closure with three arguments, returning an exception result

Source

pub unsafe fn call_n<A: AsRef<[Raw]>>(&self, args: A) -> Result<Value, Error>

Call a closure with n arguments, returning an exception result

Source

pub unsafe fn call<const N: usize, T: FromValue>( &self, rt: &Runtime, args: [impl ToValue; N], ) -> Result<T, Error>

Call a closure with a variable number of arguments, returning and exception Result

Source

pub unsafe fn modify<V: ToValue>(&mut self, rt: &Runtime, v: V)

Modify an OCaml value in place

Source

pub unsafe fn modify_raw(&mut self, v: Raw)

Modify an OCaml value in place using a raw OCaml value as the new value

Source

pub unsafe fn is_exception_result(&self) -> bool

Determines if the current value is an exception

Source

pub unsafe fn hash_variant<S: AsRef<str>>( rt: &Runtime, name: S, a: Option<Value>, ) -> Value

Get hash variant as OCaml value

Source

pub unsafe fn method<S: AsRef<str>>( &self, rt: &Runtime, name: S, ) -> Option<Value>

Get object method

Source

pub unsafe fn seq_next(&self) -> Result<Option<(Value, Value)>, Error>

Returns the next item and the next Seq.t if available, otherwise Ok(None)

Source

pub unsafe fn exception_to_string(&self) -> Result<String, Utf8Error>

Convert an OCaml exception value to the string representation

Source

pub unsafe fn initialize(&mut self, value: Value)

Initialize OCaml value using caml_initialize

Source

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.

Source

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.

Source

pub fn root(self) -> Value

Ensure a value is rooted

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Raw> for Value

Source§

fn from(v: Raw) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Value

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.
Source§

impl FromValue for Value

Source§

fn from_value(v: Value) -> Value

Convert from OCaml value
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Value

Source§

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 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToValue for Value

Source§

fn to_value(&self, _rt: &Runtime) -> Value

Convert to OCaml value
Source§

impl Eq for Value

Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl !RefUnwindSafe for Value

§

impl !Send for Value

§

impl !Sync for Value

§

impl Unpin for Value

§

impl !UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.