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>

source

pub fn as_ref<'b>(&'b self) -> OCamlRef<'b, T>
where 'a: 'b,

Obtains an OCamlRef<T> for this value.

source

pub fn root(self) -> BoxRoot<T>

source

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.

source

pub fn to_rust<RustT>(&self) -> RustT
where RustT: FromOCaml<T>,

Converts this OCaml value into a Rust value.

source

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>>

source

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 OCaml<'static, ()>

source

pub fn unit() -> Self

Returns a value that represent OCaml’s unit value.

source§

impl<T> OCaml<'static, Option<T>>

source

pub fn none() -> Self

Returns a value that represent OCaml’s None value.

source§

impl<'a> OCaml<'a, String>

source

pub fn as_bytes(&self) -> &'a [u8]

Returns an [u8] reference to the internal bytes of this value.

source

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.

source

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>

source

pub fn as_bytes(&self) -> &'a [u8]

Returns an [u8] reference to the internal bytes of this value.

source

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.

source

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>

source

pub fn to_i64(&self) -> i64

Converts an OCaml int to an i64.

source

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.

source

pub fn of_i64( n: i64 ) -> Result<OCaml<'static, OCamlInt>, OCamlFixnumConversionError>

source

pub fn of_i32(n: i32) -> OCaml<'static, OCamlInt>

Creates an OCaml int from an i32.

source§

impl<'a> OCaml<'a, bool>

source

pub fn to_bool(&self) -> bool

Converts an OCaml boolean into a Rust boolean.

source

pub fn of_bool(b: bool) -> OCaml<'static, bool>

Creates an OCaml boolean from a Rust boolean.

source§

impl<'a, A> OCaml<'a, Option<A>>

source

pub fn is_none(&self) -> bool

Returns true if this OCaml option value is an OCaml None.

source

pub fn is_some(&self) -> bool

Returns true if this OCaml option value is an OCaml Some.

source

pub fn to_option(&self) -> Option<OCaml<'a, A>>

Converts an OCaml Option<T> value into a Rust Option<OCaml<T>>.

source§

impl<'a, A, Err> OCaml<'a, Result<A, Err>>

source

pub fn is_ok(&self) -> bool

Returns true if this OCaml result value is an OCaml Ok.

source

pub fn is_error(&self) -> bool

Returns true if this OCaml result value is an OCaml Error.

source

pub fn to_result(&self) -> Result<OCaml<'a, A>, OCaml<'a, Err>>

Converts an OCaml Result<T, E> value into a Rust Result<OCaml<T>, OCaml<E>>.

source§

impl<'a, A> OCaml<'a, OCamlList<A>>

source

pub fn nil() -> Self

Returns an OCaml nil (empty list) value.

source

pub fn is_empty(&self) -> bool

Returns true if the value is OCaml’s nil (empty list).

source

pub fn hd(&self) -> Option<OCaml<'a, A>>

Returns the head of an OCaml list.

source

pub fn tl(&self) -> Option<OCaml<'a, OCamlList<A>>>

Returns the tail of an OCaml list.

source

pub fn uncons(&self) -> Option<(OCaml<'a, A>, Self)>

Returns a tuple of the head and tail of an OCaml list.

source§

impl<'a, A, B> OCaml<'a, (A, B)>

source

pub fn to_tuple(&self) -> (OCaml<'a, A>, OCaml<'a, B>)

source

pub fn fst(&self) -> OCaml<'a, A>

source

pub fn snd(&self) -> OCaml<'a, B>

source§

impl<'a, A, B, C> OCaml<'a, (A, B, C)>

source

pub fn to_tuple(&self) -> (OCaml<'a, A>, OCaml<'a, B>, OCaml<'a, C>)

source

pub fn fst(&self) -> OCaml<'a, A>

source

pub fn snd(&self) -> OCaml<'a, B>

source

pub fn tuple_3(&self) -> OCaml<'a, C>

source§

impl<'a, A, B, C, D> OCaml<'a, (A, B, C, D)>

source

pub fn to_tuple( &self ) -> (OCaml<'a, A>, OCaml<'a, B>, OCaml<'a, C>, OCaml<'a, D>)

source

pub fn fst(&self) -> OCaml<'a, A>

source

pub fn snd(&self) -> OCaml<'a, B>

source

pub fn tuple_3(&self) -> OCaml<'a, C>

source

pub fn tuple_4(&self) -> OCaml<'a, D>

source§

impl<'a, A, B, C, D, E> OCaml<'a, (A, B, C, D, E)>

source

pub fn to_tuple( &self ) -> (OCaml<'a, A>, OCaml<'a, B>, OCaml<'a, C>, OCaml<'a, D>, OCaml<'a, E>)

source

pub fn fst(&self) -> OCaml<'a, A>

source

pub fn snd(&self) -> OCaml<'a, B>

source

pub fn tuple_3(&self) -> OCaml<'a, C>

source

pub fn tuple_4(&self) -> OCaml<'a, D>

source

pub fn tuple_5(&self) -> OCaml<'a, E>

source§

impl<'a, A, B, C, D, E, F> OCaml<'a, (A, B, C, D, E, F)>

source

pub fn to_tuple( &self ) -> (OCaml<'a, A>, OCaml<'a, B>, OCaml<'a, C>, OCaml<'a, D>, OCaml<'a, E>, OCaml<'a, F>)

source

pub fn fst(&self) -> OCaml<'a, A>

source

pub fn snd(&self) -> OCaml<'a, B>

source

pub fn tuple_3(&self) -> OCaml<'a, C>

source

pub fn tuple_4(&self) -> OCaml<'a, D>

source

pub fn tuple_5(&self) -> OCaml<'a, E>

source

pub fn tuple_6(&self) -> OCaml<'a, F>

source§

impl<'a, A, B, C, D, E, F, G> OCaml<'a, (A, B, C, D, E, F, G)>

source

pub fn to_tuple( &self ) -> (OCaml<'a, A>, OCaml<'a, B>, OCaml<'a, C>, OCaml<'a, D>, OCaml<'a, E>, OCaml<'a, F>, OCaml<'a, G>)

source

pub fn fst(&self) -> OCaml<'a, A>

source

pub fn snd(&self) -> OCaml<'a, B>

source

pub fn tuple_3(&self) -> OCaml<'a, C>

source

pub fn tuple_4(&self) -> OCaml<'a, D>

source

pub fn tuple_5(&self) -> OCaml<'a, E>

source

pub fn tuple_6(&self) -> OCaml<'a, F>

source

pub fn tuple_7(&self) -> OCaml<'a, G>

source§

impl<'a, A, B, C, D, E, F, G, H> OCaml<'a, (A, B, C, D, E, F, G, H)>

source

pub fn to_tuple( &self ) -> (OCaml<'a, A>, OCaml<'a, B>, OCaml<'a, C>, OCaml<'a, D>, OCaml<'a, E>, OCaml<'a, F>, OCaml<'a, G>, OCaml<'a, H>)

source

pub fn fst(&self) -> OCaml<'a, A>

source

pub fn snd(&self) -> OCaml<'a, B>

source

pub fn tuple_3(&self) -> OCaml<'a, C>

source

pub fn tuple_4(&self) -> OCaml<'a, D>

source

pub fn tuple_5(&self) -> OCaml<'a, E>

source

pub fn tuple_6(&self) -> OCaml<'a, F>

source

pub fn tuple_7(&self) -> OCaml<'a, G>

source

pub fn tuple_8(&self) -> OCaml<'a, H>

source§

impl<'a, A, B, C, D, E, F, G, H, I> OCaml<'a, (A, B, C, D, E, F, G, H, I)>

source

pub fn to_tuple( &self ) -> (OCaml<'a, A>, OCaml<'a, B>, OCaml<'a, C>, OCaml<'a, D>, OCaml<'a, E>, OCaml<'a, F>, OCaml<'a, G>, OCaml<'a, H>, OCaml<'a, I>)

source

pub fn fst(&self) -> OCaml<'a, A>

source

pub fn snd(&self) -> OCaml<'a, B>

source

pub fn tuple_3(&self) -> OCaml<'a, C>

source

pub fn tuple_4(&self) -> OCaml<'a, D>

source

pub fn tuple_5(&self) -> OCaml<'a, E>

source

pub fn tuple_6(&self) -> OCaml<'a, F>

source

pub fn tuple_7(&self) -> OCaml<'a, G>

source

pub fn tuple_8(&self) -> OCaml<'a, H>

source

pub fn tuple_9(&self) -> OCaml<'a, I>

source§

impl<'a, A: BigarrayElt> OCaml<'a, Array1<A>>

source

pub fn len(&self) -> usize

Returns the number of items in self

source

pub fn is_empty(&self) -> bool

Returns true when self.len() == 0

source

pub fn as_slice(&self) -> &[A]

Get underlying data as Rust slice

source§

impl<'a> OCaml<'a, OCamlException>

source

pub fn message(&self) -> Option<String>

If the exception has a single argument of type string, extracts and returns it. Examples of such exceptions are Failure of string (raised via the failwith OCaml function, or the caml_raise_with_string C function) or Invalid_argument of string.

Trait Implementations§

source§

impl<'a, A: BigarrayElt> Borrow<[A]> for OCaml<'a, Array1<A>>

source§

fn borrow(&self) -> &[A]

Immutably borrows from an owned value. Read more
source§

impl<'a, A: 'static> Borrow<A> for OCaml<'a, DynBox<A>>

source§

fn borrow(&self) -> &A

Immutably borrows from an owned value. Read more
source§

impl<'a, T> Clone for OCaml<'a, T>

source§

fn clone(&self) -> Self

Returns a copy 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<'a, T> Deref for OCaml<'a, T>

§

type Target = OCamlCell<T>

The resulting type after dereferencing.
source§

fn deref(&self) -> OCamlRef<'_, T>

Dereferences the value.
source§

impl<'a, T> Copy for OCaml<'a, T>

Auto Trait Implementations§

§

impl<'a, T> RefUnwindSafe for OCaml<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for OCaml<'a, T>
where T: Sync,

§

impl<'a, T> Sync for OCaml<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for OCaml<'a, T>

§

impl<'a, T> UnwindSafe for OCaml<'a, T>
where T: RefUnwindSafe,

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> 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,

§

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>,

§

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>,

§

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.