Struct ocaml::Value[][src]

pub struct Value(pub Root);

Value wraps the native OCaml value type

Implementations

impl Value[src]

pub fn raw(&self) -> Raw[src]

Get raw OCaml value

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

Returns a named value registered by OCaml

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

Allocate a new value with the given size and tag.

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

Allocate a new tuple value

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

Allocate a new small value with the given size and tag

pub unsafe fn alloc_final<T>(
    finalizer: unsafe extern "C" fn(_: Raw),
    cfg: Option<(usize, usize)>
) -> Value
[src]

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.

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

Allocate custom value

pub unsafe fn alloc_abstract_ptr<T>(ptr: *mut T) -> Value[src]

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

pub unsafe fn new(v: impl Into<Value>) -> Value[src]

Create a new Value from an existing OCaml value

pub unsafe fn array_length(&self) -> usize[src]

Get array length

pub unsafe fn register_global_root(&mut self)[src]

See caml_register_global_root

pub unsafe fn remove_global_root(&mut self)[src]

Set caml_remove_global_root

pub unsafe fn tag(&self) -> Tag[src]

Get the tag for the underlying OCaml value

pub unsafe fn bool(b: bool) -> Value[src]

Convert a boolean to OCaml value

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

Allocate and copy a string value

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

Allocate and copy a byte array value

pub unsafe fn of_str(s: &str) -> Value[src]

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

pub unsafe fn of_bytes(s: &[u8]) -> Value[src]

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

pub unsafe fn some<V: IntoValue>(rt: &Runtime, v: V) -> Value[src]

OCaml Some value

pub fn none() -> Value[src]

OCaml None value

pub fn unit() -> Value[src]

OCaml Unit value

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

Create a variant value

pub unsafe fn result_ok(rt: &Runtime, value: impl Into<Value>) -> Value[src]

Result.Ok value

pub unsafe fn result_error(rt: &Runtime, value: impl Into<Value>) -> Value[src]

Result.Error value

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

Create an OCaml int

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

Create an OCaml int

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

Create an OCaml Int64 from i64

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

Create an OCaml Int32 from i32

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

Create an OCaml Nativeint from isize

pub unsafe fn float(d: f64) -> Value[src]

Create an OCaml Float from f64

pub unsafe fn is_block(&self) -> bool[src]

Check if a Value is an integer or block, returning true if the underlying value is a block

pub unsafe fn is_long(&self) -> bool[src]

Check if a Value is an integer or block, returning true if the underlying value is an integer

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

Get index of underlying OCaml block value

pub unsafe fn store_field<V: IntoValue>(
    &mut self,
    rt: &Runtime,
    i: Size,
    val: V
)
[src]

Set index of underlying OCaml block value

pub unsafe fn int_val(&self) -> isize[src]

Convert an OCaml int to isize

pub unsafe fn float_val(&self) -> f64[src]

Convert an OCaml Float to f64

pub unsafe fn int32_val(&self) -> i32[src]

Convert an OCaml Int32 to i32

pub unsafe fn int64_val(&self) -> i64[src]

Convert an OCaml Int64 to i64

pub unsafe fn nativeint_val(&self) -> isize[src]

Convert an OCaml Nativeint to isize

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

Get pointer to data stored in an OCaml custom value

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

Get mutable pointer to data stored in an OCaml custom value

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

Get pointer to the pointer contained by Value

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

Get mutable pointer to the pointer contained by Value

pub unsafe fn string_val(&self) -> &str[src]

Get underlying string pointer

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

Get underlying bytes pointer

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

Get mutable string pointer

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

Get mutable bytes pointer

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

Extract OCaml exception

pub unsafe fn check_result(self) -> Result<Value, Error>[src]

Convert value to Rust Result type depending on if the value is an exception or not

pub unsafe fn call<A: IntoValue>(
    &self,
    rt: &Runtime,
    arg1: A
) -> Result<Value, Error>
[src]

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

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

Call a closure with two arguments, returning an exception value

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

Call a closure with three arguments, returning an exception value

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

Call a closure with n arguments, returning an exception value

pub unsafe fn modify<V: IntoValue>(&mut self, rt: &Runtime, v: V)[src]

Modify an OCaml value in place

pub unsafe fn is_exception_result(&self) -> bool[src]

Determines if the current value is an exception

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

Get hash variant as OCaml value

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

Get object method

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

Initialize OCaml value using caml_initialize

pub unsafe fn deep_clone_to_ocaml(self) -> Self[src]

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.

pub unsafe fn deep_clone_to_rust(&self) -> Self[src]

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

impl Clone for Value[src]

fn clone(&self) -> Value[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Value[src]

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

Formats the value using the given formatter. Read more

impl<'a, T> FromOCaml<T> for Value[src]

fn from_ocaml(v: OCaml<'_, T>) -> Value[src]

Convert from OCaml value.

impl<'a> FromValue<'a> for Value[src]

fn from_value(v: Value) -> Value[src]

Convert from OCaml value

impl<'a> IntoValue for &Value[src]

fn into_value(self, _rt: &Runtime) -> Value[src]

Convert to OCaml value

impl IntoValue for Value[src]

fn into_value(self, _rt: &Runtime) -> Value[src]

Convert to OCaml value

impl PartialEq<Value> for Value[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Value) -> bool[src]

This method tests for !=.

impl PartialOrd<Value> for Value[src]

fn partial_cmp(&self, other: &Value) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T> ToOCaml<T> for Value[src]

fn to_ocaml<'a>(&self, gc: &'a mut Runtime) -> OCaml<'a, T>[src]

Convert to OCaml value.

fn to_boxroot(&self, cr: &mut OCamlRuntime) -> BoxRoot<T>[src]

Convert to OCaml value. Return an already rooted value as BoxRoot<T>.

impl StructuralPartialEq for Value[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.