Struct wiggle_generate::config::AsyncConf
source · pub struct AsyncConf { /* private fields */ }
Expand description
Modules and funcs that have async signatures
Implementations§
source§impl AsyncConf
impl AsyncConf
sourcepub fn get(&self, module: &str, function: &str) -> Asyncness
pub fn get(&self, module: &str, function: &str) -> Asyncness
Examples found in repository?
More examples
src/wasmtime.rs (line 25)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
pub fn link_module(
module: &witx::Module,
target_path: Option<&syn::Path>,
settings: &CodegenSettings,
) -> TokenStream {
let module_ident = names::module(&module.name);
let send_bound = if settings.async_.contains_async(module) {
quote! { + Send, T: Send }
} else {
quote! {}
};
let mut bodies = Vec::new();
let mut bounds = HashSet::new();
for f in module.funcs() {
let asyncness = settings.async_.get(module.name.as_str(), f.name.as_str());
bodies.push(generate_func(&module, &f, target_path, asyncness));
let bound = func_bounds(module, &f, settings);
for b in bound {
bounds.insert(b);
}
}
let ctx_bound = if let Some(target_path) = target_path {
let bounds = bounds
.into_iter()
.map(|b| quote!(#target_path::#module_ident::#b));
quote!( #(#bounds)+* #send_bound )
} else {
let bounds = bounds.into_iter();
quote!( #(#bounds)+* #send_bound )
};
let func_name = if target_path.is_none() {
format_ident!("add_to_linker")
} else {
format_ident!("add_{}_to_linker", module_ident)
};
quote! {
/// Adds all instance items to the specified `Linker`.
pub fn #func_name<T, U>(
linker: &mut wiggle::wasmtime_crate::Linker<T>,
get_cx: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wiggle::anyhow::Result<()>
where
U: #ctx_bound #send_bound
{
#(#bodies)*
Ok(())
}
}
}
sourcepub fn contains_async(&self, module: &Module) -> bool
pub fn contains_async(&self, module: &Module) -> bool
Examples found in repository?
src/wasmtime.rs (line 16)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
pub fn link_module(
module: &witx::Module,
target_path: Option<&syn::Path>,
settings: &CodegenSettings,
) -> TokenStream {
let module_ident = names::module(&module.name);
let send_bound = if settings.async_.contains_async(module) {
quote! { + Send, T: Send }
} else {
quote! {}
};
let mut bodies = Vec::new();
let mut bounds = HashSet::new();
for f in module.funcs() {
let asyncness = settings.async_.get(module.name.as_str(), f.name.as_str());
bodies.push(generate_func(&module, &f, target_path, asyncness));
let bound = func_bounds(module, &f, settings);
for b in bound {
bounds.insert(b);
}
}
let ctx_bound = if let Some(target_path) = target_path {
let bounds = bounds
.into_iter()
.map(|b| quote!(#target_path::#module_ident::#b));
quote!( #(#bounds)+* #send_bound )
} else {
let bounds = bounds.into_iter();
quote!( #(#bounds)+* #send_bound )
};
let func_name = if target_path.is_none() {
format_ident!("add_to_linker")
} else {
format_ident!("add_{}_to_linker", module_ident)
};
quote! {
/// Adds all instance items to the specified `Linker`.
pub fn #func_name<T, U>(
linker: &mut wiggle::wasmtime_crate::Linker<T>,
get_cx: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wiggle::anyhow::Result<()>
where
U: #ctx_bound #send_bound
{
#(#bodies)*
Ok(())
}
}
}