[][src]Trait gluon::ThreadExt

pub trait ThreadExt: Send + Sync {
    fn get_database(&self) -> DatabaseSnapshot;
fn get_database_mut(&self) -> DatabaseMut; fn run_io(&self, run: bool) { ... }
fn module_compiler<'a, 'b>(
        &'a self,
        database: impl Into<OwnedDb<'a, dyn Compilation + '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>> { ... }
#[must_use] 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
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait,
        Self: 'async_trait
, { ... }
fn typecheck_str(
        &self,
        file: &str,
        expr_str: &str,
        expected_type: Option<&ArcType>
    ) -> Result<(Arc<OwnedExpr<Symbol>>, ArcType)> { ... }
#[must_use] 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
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait,
        Self: 'async_trait
, { ... }
#[must_use] 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
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait,
        Self: 'async_trait
, { ... }
#[must_use] 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,
        S::Error: 'static,
        S: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
, { ... }
#[must_use] 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,
        E: Send + Sync,
        'vm: 'async_trait,
        D: 'async_trait,
        E: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
#[must_use] 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
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
, { ... }
fn load_script(&self, filename: &str, input: &str) -> Result<()> { ... }
#[must_use] 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
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
, { ... }
fn load_file<'vm>(&'vm self, filename: &str) -> Result<()> { ... }
#[must_use] fn load_file_async<'vm, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        filename: &'life1 str
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
    where
        'vm: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: '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
, { ... }
#[must_use] 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,
        'vm: 'async_trait,
        T: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn format_expr(
        &self,
        formatter: &mut Formatter,
        file: &str,
        input: &str
    ) -> Result<String> { ... }
#[must_use] 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
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait,
        Self: 'async_trait
, { ... } }

Extension trait which provides methods to load and execute gluon code

Required methods

Loading content...

Provided methods

fn run_io(&self, run: bool)

fn module_compiler<'a, 'b>(
    &'a self,
    database: impl Into<OwnedDb<'a, dyn Compilation + 'b>>
) -> ModuleCompiler<'a, 'b>

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

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

#[must_use]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
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
    Self: 'async_trait, 

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

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

#[must_use]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
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
    Self: 'async_trait, 

#[must_use]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
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
    Self: 'async_trait, 

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

#[must_use]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,
    S::Error: 'static,
    S: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 

Compiles the source code expr_str into bytecode serialized using serializer

#[must_use]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,
    E: Send + Sync,
    'vm: 'async_trait,
    D: 'async_trait,
    E: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    Self: '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

#[must_use]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
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 

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

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.

#[must_use]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
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 

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

Loads filename and compiles and runs its input by calling load_script

#[must_use]fn load_file_async<'vm, 'life0, 'life1, 'async_trait>(
    &'life0 self,
    filename: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
    'vm: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    Self: '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, 

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

#[must_use]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,
    'vm: 'async_trait,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    Self: '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);
}

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

#[must_use]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
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
    Self: 'async_trait, 

Loading content...

Implementors

impl ThreadExt for Thread[src]

Loading content...