Trait gluon::ThreadExt

source ·
pub trait ThreadExt: Send + Sync {
Show 21 methods // Required methods fn get_database(&self) -> Snapshot<CompilerDatabase>; fn get_database_mut(&self) -> DatabaseMut; // Provided methods fn run_io(&self, run: bool) { ... } fn module_compiler<'a, 'b>( &'a self, database: impl IntoDb<'a, 'b> ) -> ModuleCompiler<'a, 'b> { ... } fn parse_expr( &self, type_cache: &TypeCache<Symbol, ArcType>, file: &str, expr_str: &str ) -> StdResult<OwnedExpr<Symbol>, InFile<Error>> { ... } fn parse_partial_expr( &self, type_cache: &TypeCache<Symbol, ArcType>, file: &str, expr_str: &str ) -> SalvageResult<OwnedExpr<Symbol>, InFile<Error>> { ... } fn typecheck_expr<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, file: &'life1 str, expr_str: &'life2 str, expr: &'life3 mut OwnedExpr<Symbol> ) -> Pin<Box<dyn Future<Output = Result<ArcType>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn typecheck_str( &self, file: &str, expr_str: &str, expected_type: Option<&ArcType> ) -> Result<(Arc<OwnedExpr<Symbol>>, ArcType)> { ... } fn typecheck_str_async<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, file: &'life1 str, expr_str: &'life2 str, expected_type: Option<&'life3 ArcType> ) -> Pin<Box<dyn Future<Output = Result<(Arc<OwnedExpr<Symbol>>, ArcType)>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn compile_script<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, filename: &'life1 str, expr_str: &'life2 str, expr: &'life3 OwnedExpr<Symbol> ) -> Pin<Box<dyn Future<Output = Result<CompiledModule>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn compile_to_bytecode<'life0, 'life1, 'life2, 'async_trait, S>( &'life0 self, name: &'life1 str, expr_str: &'life2 str, serializer: S ) -> Pin<Box<dyn Future<Output = StdResult<S::Ok, Either<Error, S::Error>>> + Send + 'async_trait>> where S: Serializer + Send + 'async_trait, S::Error: 'static, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn load_bytecode<'vm, 'life0, 'life1, 'async_trait, D, E>( &'life0 self, name: &'life1 str, deserializer: D ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where D: for<'de> Deserializer<'de, Error = E> + Send + 'async_trait, E: Send + Sync + 'async_trait, Self: 'async_trait, 'vm: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn extract_metadata<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, file: &'life1 str, expr_str: &'life2 str ) -> Pin<Box<dyn Future<Output = Result<(Arc<OwnedExpr<Symbol>>, ArcType, Arc<Metadata>)>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn load_script(&self, filename: &str, input: &str) -> Result<()> { ... } fn load_script_async<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, filename: &'life1 str, input: &'life2 str ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn load_file<'vm>(&'vm self, filename: &str) -> Result<()> { ... } fn load_file_async<'vm, 'life0, 'life1, 'async_trait>( &'life0 self, filename: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'vm: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn run_expr<'vm, T>( &'vm self, name: &str, expr_str: &str ) -> Result<(T, ArcType)> where T: for<'value> Getable<'vm, 'value> + VmType + Send + 'vm { ... } fn run_expr_async<'vm, 'life0, 'life1, 'async_trait, T>( &'vm self, name: &'life0 str, expr_str: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<(T, ArcType)>> + Send + 'async_trait>> where T: for<'value> Getable<'vm, 'value> + VmType + Send + 'vm + 'async_trait, Self: 'async_trait, 'vm: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn format_expr( &self, formatter: &mut Formatter, file: &str, input: &str ) -> Result<String> { ... } fn format_expr_async<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, formatter: &'life1 mut Formatter, file: &'life2 str, input: &'life3 str ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... }
}
Expand description

Extension trait which provides methods to load and execute gluon code

Required Methods§

source

fn get_database(&self) -> Snapshot<CompilerDatabase>

source

fn get_database_mut(&self) -> DatabaseMut

Provided Methods§

source

fn run_io(&self, run: bool)

source

fn module_compiler<'a, 'b>( &'a self, database: impl IntoDb<'a, 'b> ) -> ModuleCompiler<'a, 'b>

source

fn parse_expr( &self, type_cache: &TypeCache<Symbol, ArcType>, file: &str, expr_str: &str ) -> StdResult<OwnedExpr<Symbol>, InFile<Error>>

Parse expr_str, returning an expression if successful

source

fn parse_partial_expr( &self, type_cache: &TypeCache<Symbol, ArcType>, file: &str, expr_str: &str ) -> SalvageResult<OwnedExpr<Symbol>, InFile<Error>>

Parse input, returning an expression if successful

source

fn typecheck_expr<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, file: &'life1 str, expr_str: &'life2 str, expr: &'life3 mut OwnedExpr<Symbol> ) -> Pin<Box<dyn Future<Output = Result<ArcType>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Parse and typecheck expr_str returning the typechecked expression and type of the expression

source

fn typecheck_str( &self, file: &str, expr_str: &str, expected_type: Option<&ArcType> ) -> Result<(Arc<OwnedExpr<Symbol>>, ArcType)>

source

fn typecheck_str_async<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, file: &'life1 str, expr_str: &'life2 str, expected_type: Option<&'life3 ArcType> ) -> Pin<Box<dyn Future<Output = Result<(Arc<OwnedExpr<Symbol>>, ArcType)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

source

fn compile_script<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, filename: &'life1 str, expr_str: &'life2 str, expr: &'life3 OwnedExpr<Symbol> ) -> Pin<Box<dyn Future<Output = Result<CompiledModule>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Compiles expr into a function which can be added and run by the vm

source

fn compile_to_bytecode<'life0, 'life1, 'life2, 'async_trait, S>( &'life0 self, name: &'life1 str, expr_str: &'life2 str, serializer: S ) -> Pin<Box<dyn Future<Output = StdResult<S::Ok, Either<Error, S::Error>>> + Send + 'async_trait>>
where S: Serializer + Send + 'async_trait, S::Error: 'static, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Compiles the source code expr_str into bytecode serialized using serializer

source

fn load_bytecode<'vm, 'life0, 'life1, 'async_trait, D, E>( &'life0 self, name: &'life1 str, deserializer: D ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where D: for<'de> Deserializer<'de, Error = E> + Send + 'async_trait, E: Send + Sync + 'async_trait, Self: 'async_trait, 'vm: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Loads bytecode from a Deserializer and stores it into the module name.

load_script is equivalent to compile_to_bytecode followed by load_bytecode

source

fn extract_metadata<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, file: &'life1 str, expr_str: &'life2 str ) -> Pin<Box<dyn Future<Output = Result<(Arc<OwnedExpr<Symbol>>, ArcType, Arc<Metadata>)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Parses and typechecks expr_str followed by extracting metadata from the created expression

source

fn load_script(&self, filename: &str, input: &str) -> Result<()>

Compiles input and if it is successful runs the resulting code and stores the resulting value in the vm.

If at any point the function fails the resulting error is returned and nothing is added to the VM.

source

fn load_script_async<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, filename: &'life1 str, input: &'life2 str ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

source

fn load_file<'vm>(&'vm self, filename: &str) -> Result<()>

Loads filename and compiles and runs its input by calling load_script

source

fn load_file_async<'vm, 'life0, 'life1, 'async_trait>( &'life0 self, filename: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'vm: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

source

fn run_expr<'vm, T>( &'vm self, name: &str, expr_str: &str ) -> Result<(T, ArcType)>
where T: for<'value> Getable<'vm, 'value> + VmType + Send + 'vm,

Compiles and runs the expression in expr_str. If successful the value from running the expression is returned

Examples

Import from gluon’s standard library and evaluate a string

let vm = new_vm();
let (result, _) = vm
    .run_expr::<String>(
        "example",
        " let string  = import! \"std/string.glu\" in string.trim \"  Hello world  \t\" "
    )
    .unwrap();
assert_eq!(result, "Hello world");
}).unwrap().join().unwrap()
source

fn run_expr_async<'vm, 'life0, 'life1, 'async_trait, T>( &'vm self, name: &'life0 str, expr_str: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<(T, ArcType)>> + Send + 'async_trait>>
where T: for<'value> Getable<'vm, 'value> + VmType + Send + 'vm + 'async_trait, Self: 'async_trait, 'vm: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Compiles and runs the expression in expr_str. If successful the value from running the expression is returned

Examples

Import from gluon’s standard library and evaluate a string

let vm = new_vm_async().await;
let result = vm
    .run_expr_async::<String>("example",
        " let string  = import! \"std/string.glu\" in string.trim \"    Hello world  \t\" ")
    .await
    .unwrap();
let expected = ("Hello world".to_string(), Type::string());

assert_eq!(result, expected);
}
source

fn format_expr( &self, formatter: &mut Formatter, file: &str, input: &str ) -> Result<String>

source

fn format_expr_async<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, formatter: &'life1 mut Formatter, file: &'life2 str, input: &'life3 str ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Object Safety§

This trait is not object safe.

Implementors§