Struct gluon::RootedThread
source · 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
impl RootedThread
sourcepub fn new() -> RootedThread
pub fn new() -> RootedThread
Creates a new virtual machine with an empty global environment
pub fn with_global_state(global_state: GlobalVmState) -> RootedThread
sourcepub fn into_raw(self) -> *const Thread
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
sourcepub unsafe fn from_raw(ptr: *const Thread) -> RootedThread
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>§
sourcepub fn new_thread(&self) -> Result<RootedThread, Error>
pub fn new_thread(&self) -> Result<RootedThread, Error>
Spawns a new gluon thread with its own stack and heap but while still sharing the same global environment
sourcepub fn root_thread(&self) -> RootedThread
pub fn root_thread(&self) -> RootedThread
Roots self
, extending the lifetime of this thread until at least the returned
RootedThread
is droppped
pub fn spawner(&self) -> Option<&(dyn Spawn + Send + Sync)>
sourcepub fn get_global<'vm, T>(&'vm self, name: &str) -> Result<T, Error>
pub fn get_global<'vm, T>(&'vm self, name: &str) -> Result<T, Error>
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.
pub fn get_global_type(&self, name: &str) -> Result<ArcType, Error>
sourcepub fn find_type_info(
&self,
name: &str
) -> Result<Alias<Symbol, ArcType>, Error>
pub fn find_type_info( &self, name: &str ) -> Result<Alias<Symbol, ArcType>, Error>
Retrieves type information about the type name
. Types inside records can be accessed
using dot notation (std.prelude.Option)
sourcepub fn register_type<T>(
&self,
name: &str,
args: &[&str]
) -> Result<ArcType, Error>
pub fn register_type<T>( &self, name: &str, args: &[&str] ) -> Result<ArcType, Error>
Registers the type T
as being a gluon type called name
with generic arguments args
pub fn register_type_as( &self, name: Symbol, alias: Alias<Symbol, ArcType>, id: TypeId ) -> Result<ArcType, Error>
pub fn get_cache_alias(&self, name: &str) -> Option<ArcType>
pub fn cache_alias(&self, alias: Alias<Symbol, ArcType>) -> ArcType
sourcepub fn get_env<'b>(&'b self) -> VmEnvInstance<'b>
pub fn get_env<'b>(&'b self) -> VmEnvInstance<'b>
Locks and retrieves the global environment of the vm
sourcepub fn get_macros(&self) -> &MacroEnv
pub fn get_macros(&self) -> &MacroEnv
Retrieves the macros defined for this vm
sourcepub fn push<'vm, T>(&'vm self, v: T) -> Result<(), Error>where
T: Pushable<'vm>,
pub fn push<'vm, T>(&'vm self, v: T) -> Result<(), Error>where
T: Pushable<'vm>,
Pushes a value to the top of the stack
pub fn allocated_memory(&self) -> usize
pub fn set_memory_limit(&self, memory_limit: usize)
pub fn interrupt(&self)
pub fn interrupted(&self) -> bool
pub fn current_context(&self) -> ActiveThread<'_>
Trait Implementations§
source§impl Clone for RootedThread
impl Clone for RootedThread
source§fn clone(&self) -> RootedThread
fn clone(&self) -> RootedThread
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RootedThread
impl Debug for RootedThread
source§impl Deref for RootedThread
impl Deref for RootedThread
source§impl<'de, 'gc> DeserializeState<'de, DeSeed<'gc>> for RootedThread
impl<'de, 'gc> DeserializeState<'de, DeSeed<'gc>> for RootedThread
source§fn deserialize_state<D>(
seed: &mut DeSeed<'gc>,
deserializer: D
) -> Result<RootedThread, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize_state<D>(
seed: &mut DeSeed<'gc>,
deserializer: D
) -> Result<RootedThread, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Self
using seed
and the deserializer
source§impl Drop for RootedThread
impl Drop for RootedThread
source§impl<'vm, 'value> Getable<'vm, 'value> for RootedThread
impl<'vm, 'value> Getable<'vm, 'value> for RootedThread
type Proxy = Variants<'value>
fn to_proxy( _vm: &'vm Thread, value: Variants<'value> ) -> Result<<RootedThread as Getable<'vm, 'value>>::Proxy, Error>
fn from_proxy( vm: &'vm Thread, proxy: &'value mut <RootedThread as Getable<'vm, 'value>>::Proxy ) -> RootedThread
fn from_value(_: &'vm Thread, value: Variants<'value>) -> RootedThread
source§impl<'vm> Pushable<'vm> for RootedThread
impl<'vm> Pushable<'vm> for RootedThread
source§fn vm_push(self, context: &mut ActiveThread<'vm>) -> Result<(), Error>
fn vm_push(self, context: &mut ActiveThread<'vm>) -> Result<(), Error>
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 intactfn status_push(self, context: &mut ActiveThread<'vm>) -> Statuswhere
Self: Sized,
unsafe fn marshal_unrooted(self, vm: &'vm Thread) -> Result<Value, Error>where
Self: Sized,
fn marshal<T>(self, vm: &'vm Thread) -> Result<RootedValue<T>, Error>
source§impl SerializeState<SeSeed> for RootedThread
impl SerializeState<SeSeed> for RootedThread
source§fn serialize_state<__S>(
&self,
__serializer: __S,
__seed: &SeSeed
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize_state<__S>(
&self,
__serializer: __S,
__seed: &SeSeed
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
self
source§impl Trace for RootedThread
impl Trace for RootedThread
source§impl<'a> VmRoot<'a> for RootedThread
impl<'a> VmRoot<'a> for RootedThread
fn new_root(thread: &'a Thread) -> RootedThread
source§impl VmRootInternal for RootedThread
impl VmRootInternal for RootedThread
source§impl VmType for RootedThread
impl VmType for RootedThread
fn make_forall_type(vm: &Thread) -> ArcType
source§const EXTRA_ARGS: u32 = 0u32
const EXTRA_ARGS: u32 = 0u32
Auto Trait Implementations§
impl !RefUnwindSafe for RootedThread
impl Send for RootedThread
impl Sync for RootedThread
impl Unpin for RootedThread
impl !UnwindSafe for RootedThread
Blanket Implementations§
source§impl<'vm, T> AsyncPushable<'vm> for Twhere
T: Pushable<'vm>,
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>>
fn async_push( self, context: &mut ActiveThread<'vm>, lock: Lock, _: u32 ) -> Poll<Result<(), Error>>
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 morefn async_status_push(
self,
context: &mut ActiveThread<'vm>,
lock: Lock,
frame_index: u32
) -> Statuswhere
Self: Sized,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.