pub struct RootedThread { /* private fields */ }
Expand description

An instance of Thread which is rooted. See the Thread type for documentation on interacting with the type.

Implementations§

source§

impl RootedThread

source

pub fn new() -> RootedThread

Creates a new virtual machine with an empty global environment

source

pub fn with_global_state(global_state: GlobalVmState) -> RootedThread

source

pub fn into_raw(self) -> *const Thread

Converts a RootedThread into a raw pointer allowing to be passed through a C api. The reference count for the thread is not modified

source

pub unsafe fn from_raw(ptr: *const Thread) -> RootedThread

Converts a raw pointer into a RootedThread. The reference count for the thread is not modified so it is up to the caller to ensure that the count is correct.

Methods from Deref<Target = Thread>§

source

pub fn new_thread(&self) -> Result<RootedThread>

Spawns a new gluon thread with its own stack and heap but while still sharing the same global environment

source

pub fn root_thread(&self) -> RootedThread

Roots self, extending the lifetime of this thread until at least the returned RootedThread is droppped

source

pub fn spawner(&self) -> Option<&(dyn Spawn + Send + Sync)>

source

pub fn get_global<'vm, T>(&'vm self, name: &str) -> Result<T>where T: for<'value> Getable<'vm, 'value> + VmType,

Retrieves the global called name.

Examples

Bind the (+) function in gluon’s prelude standard library to an add function in rust



let vm = new_vm_async().await;

vm.run_expr_async::<OpaqueValue<&Thread, Hole>>("example", r#" import! std.int "#)
    .await
    .unwrap_or_else(|err| panic!("{}", err));
let mut add: FunctionRef<fn(i32, i32) -> i32> =
    vm.get_global("std.int.num.(+)").unwrap();
let result = add.call_async(1, 2).await;
assert_eq!(result, Ok(3));
Errors

if the global does not exist or it does not have the correct type.

source

pub fn get_global_type(&self, name: &str) -> Result<ArcType>

source

pub fn find_type_info(&self, name: &str) -> Result<Alias<Symbol, ArcType>>

Retrieves type information about the type name. Types inside records can be accessed using dot notation (std.prelude.Option)

source

pub fn get_type<T: ?Sized + Any>(&self) -> Option<ArcType>

Returns the gluon type that was bound to T

source

pub fn register_type<T: ?Sized + Any>( &self, name: &str, args: &[&str] ) -> Result<ArcType>

Registers the type T as being a gluon type called name with generic arguments args

source

pub fn register_type_as( &self, name: Symbol, alias: Alias<Symbol, ArcType>, id: TypeId ) -> Result<ArcType>

source

pub fn get_cache_alias(&self, name: &str) -> Option<ArcType>

source

pub fn cache_alias(&self, alias: Alias<Symbol, ArcType>) -> ArcType

source

pub fn get_env<'b>(&'b self) -> VmEnvInstance<'b>

Locks and retrieves the global environment of the vm

source

pub fn get_macros(&self) -> &MacroEnv

Retrieves the macros defined for this vm

source

pub fn collect(&self)

Runs a garbage collection.

source

pub fn push<'vm, T>(&'vm self, v: T) -> Result<()>where T: Pushable<'vm>,

Pushes a value to the top of the stack

source

pub fn pop(&self)

Removes the top value from the stack

source

pub fn allocated_memory(&self) -> usize

source

pub fn set_memory_limit(&self, memory_limit: usize)

source

pub fn interrupt(&self)

source

pub fn interrupted(&self) -> bool

source

pub fn current_context(&self) -> ActiveThread<'_>

Trait Implementations§

source§

impl Clone for RootedThread

source§

fn clone(&self) -> RootedThread

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 Debug for RootedThread

source§

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

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

impl Deref for RootedThread

§

type Target = Thread

The resulting type after dereferencing.
source§

fn deref(&self) -> &Thread

Dereferences the value.
source§

impl<'de, 'gc> DeserializeState<'de, DeSeed<'gc>> for RootedThread

source§

fn deserialize_state<D>( seed: &mut DeSeed<'gc>, deserializer: D ) -> StdResult<Self, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,

Deserializes Self using seed and the deserializer
source§

impl Drop for RootedThread

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'vm, 'value> Getable<'vm, 'value> for RootedThread

§

type Proxy = Variants<'value>

source§

fn to_proxy(_vm: &'vm Thread, value: Variants<'value>) -> Result<Self::Proxy>

source§

fn from_proxy(vm: &'vm Thread, proxy: &'value mut Self::Proxy) -> Self

source§

fn from_value(_: &'vm Thread, value: Variants<'value>) -> Self

source§

impl<'vm> Pushable<'vm> for RootedThread

source§

fn vm_push(self, context: &mut ActiveThread<'vm>) -> Result<()>

Pushes self to stack. If the call is successful a single element should have been added to the stack and Ok(()) should be returned. If the call is unsuccessful Status:Error should be returned and the stack should be left intact
source§

fn status_push(self, context: &mut ActiveThread<'vm>) -> Statuswhere Self: Sized,

source§

unsafe fn marshal_unrooted(self, vm: &'vm Thread) -> Result<Value>where Self: Sized,

source§

fn marshal<T>(self, vm: &'vm Thread) -> Result<RootedValue<T>>where Self: Sized, T: VmRoot<'vm>,

source§

impl SerializeState<SeSeed> for RootedThread

source§

fn serialize_state<__S>( &self, __serializer: __S, __seed: &SeSeed ) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serializes self
source§

impl Trace for RootedThread

source§

unsafe fn root(&mut self)

source§

unsafe fn unroot(&mut self)

source§

fn trace(&self, gc: &mut Gc)

source§

impl<'a> VmRoot<'a> for RootedThread

source§

fn new_root(thread: &'a Thread) -> Self

source§

impl VmRootInternal for RootedThread

source§

fn root_vm(&mut self)

source§

fn unroot_vm(&mut self)

source§

unsafe fn root_value_with_self(self, value: &Value) -> RootedValue<Self>where Self: Sized,

Roots a value
source§

impl VmType for RootedThread

§

type Type = Thread

A version of Self which implements Any allowing a TypeId to be retrieved
source§

fn make_forall_type(vm: &Thread) -> ArcType

source§

fn make_type(vm: &Thread) -> ArcType

Creates an gluon type which maps to Self in rust
source§

const EXTRA_ARGS: VmIndex = 0u32

How many extra arguments a function returning this type requires. Used for abstract types which when used in return position should act like they still need more arguments before they are called

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<Id> AsId<Id> for Idwhere Id: ?Sized,

source§

fn as_id(&self) -> &Id

source§

impl<'vm, T> AsyncPushable<'vm> for Twhere T: Pushable<'vm>,

source§

fn async_push( self, context: &mut ActiveThread<'vm>, lock: Lock, _: u32 ) -> Poll<Result<(), Error>>

Pushes self to stack. If the call is successful a single element should have been added to the stack and Ok(()) should be returned. If the call is unsuccessful Status:Error should be returned and the stack should be left intact. Read more
source§

fn async_status_push( self, context: &mut ActiveThread<'vm>, lock: Lock, frame_index: VmIndex ) -> Statuswhere Self: Sized,

source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<Choices> CoproductSubsetter<CNil, HNil> for Choices

§

type Remainder = Choices

source§

fn subset( self ) -> Result<CNil, <Choices as CoproductSubsetter<CNil, HNil>>::Remainder>

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) Read more
source§

impl<T> Downcast for Twhere T: Any,

source§

fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastArc for Twhere T: Downcast + Send + Sync,

source§

fn into_arc_any(self: Arc<T, Global>) -> Arc<dyn Any + Send + Sync, Global>

source§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T, Global>) -> Arc<dyn Any + Send + Sync, Global>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<D, T> FromPtr<D> for T

source§

unsafe fn make_ptr(_: D, ptr: *mut ()) -> *mut T

source§

impl<T, U> Into<U> for Twhere 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, U, I> LiftInto<U, I> for Twhere U: LiftFrom<T, I>,

source§

fn lift_into(self) -> U

Performs the indexed conversion.
source§

impl<Source> Sculptor<HNil, HNil> for Source

§

type Remainder = Source

source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. Read more
source§

impl<T> ToOwned for Twhere 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 Twhere 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 Twhere 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.
§

impl<T> Any for Twhere T: Any,

source§

impl<T> Captures<'_> for T

§

impl<T> CloneAny for Twhere T: Any + Clone,