make stdlib functions async (#672)
* wip Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> closer Signed-off-by: Jess Frazelle <github@jessfraz.com> fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * closer Signed-off-by: Jess Frazelle <github@jessfraz.com> * closer Signed-off-by: Jess Frazelle <github@jessfraz.com> * compiles Signed-off-by: Jess Frazelle <github@jessfraz.com> * connection Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix wasm Signed-off-by: Jess Frazelle <github@jessfraz.com> * timeout Signed-off-by: Jess Frazelle <github@jessfraz.com> * remove the drop Signed-off-by: Jess Frazelle <github@jessfraz.com> * drop handle Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -79,13 +79,6 @@ fn do_stdlib_inner(
|
||||
));
|
||||
}
|
||||
|
||||
if ast.sig.asyncness.is_some() {
|
||||
errors.push(Error::new_spanned(
|
||||
&ast.sig.fn_token,
|
||||
"stdlib functions must not be async",
|
||||
));
|
||||
}
|
||||
|
||||
if ast.sig.unsafety.is_some() {
|
||||
errors.push(Error::new_spanned(
|
||||
&ast.sig.unsafety,
|
||||
@ -118,6 +111,7 @@ fn do_stdlib_inner(
|
||||
let fn_name = &ast.sig.ident;
|
||||
let fn_name_str = fn_name.to_string().replace("inner_", "");
|
||||
let fn_name_ident = format_ident!("{}", fn_name_str);
|
||||
let boxed_fn_name_ident = format_ident!("boxed_{}", fn_name_str);
|
||||
let _visibility = &ast.vis;
|
||||
|
||||
let (summary_text, description_text) = extract_doc_from_attrs(&ast.attrs);
|
||||
@ -204,7 +198,10 @@ fn do_stdlib_inner(
|
||||
syn::FnArg::Typed(pat) => pat.ty.as_ref().into_token_stream(),
|
||||
};
|
||||
|
||||
let ty_string = ty.to_string().replace('&', "").replace("mut", "").replace(' ', "");
|
||||
let mut ty_string = ty.to_string().replace('&', "").replace("mut", "").replace(' ', "");
|
||||
if ty_string.starts_with("Args") {
|
||||
ty_string = "Args".to_string();
|
||||
}
|
||||
let ty_string = ty_string.trim().to_string();
|
||||
let ty_ident = if ty_string.starts_with("Vec<") {
|
||||
let ty_string = ty_string.trim_start_matches("Vec<").trim_end_matches('>');
|
||||
@ -305,6 +302,14 @@ fn do_stdlib_inner(
|
||||
#description_doc_comment
|
||||
#const_struct
|
||||
|
||||
fn #boxed_fn_name_ident(
|
||||
args: crate::std::Args,
|
||||
) -> std::pin::Pin<
|
||||
Box<dyn std::future::Future<Output = anyhow::Result<crate::executor::MemoryItem, crate::errors::KclError>>>,
|
||||
> {
|
||||
Box::pin(#fn_name_ident(args))
|
||||
}
|
||||
|
||||
impl #docs_crate::StdLibFn for #name_ident
|
||||
{
|
||||
fn name(&self) -> String {
|
||||
@ -348,7 +353,7 @@ fn do_stdlib_inner(
|
||||
}
|
||||
|
||||
fn std_lib_fn(&self) -> crate::std::StdFn {
|
||||
#fn_name_ident
|
||||
#boxed_fn_name_ident
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> Box<dyn #docs_crate::StdLibFn> {
|
||||
|
@ -7,6 +7,18 @@ pub(crate) struct Show {}
|
||||
#[allow(non_upper_case_globals, missing_docs)]
|
||||
#[doc = "Std lib function: show"]
|
||||
pub(crate) const Show: Show = Show {};
|
||||
fn boxed_show(
|
||||
args: crate::std::Args,
|
||||
) -> std::pin::Pin<
|
||||
Box<
|
||||
dyn std::future::Future<
|
||||
Output = anyhow::Result<crate::executor::MemoryItem, crate::errors::KclError>,
|
||||
>,
|
||||
>,
|
||||
> {
|
||||
Box::pin(show(args))
|
||||
}
|
||||
|
||||
impl crate::docs::StdLibFn for Show {
|
||||
fn name(&self) -> String {
|
||||
"show".to_string()
|
||||
@ -57,7 +69,7 @@ impl crate::docs::StdLibFn for Show {
|
||||
}
|
||||
|
||||
fn std_lib_fn(&self) -> crate::std::StdFn {
|
||||
show
|
||||
boxed_show
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> Box<dyn crate::docs::StdLibFn> {
|
||||
|
@ -7,6 +7,18 @@ pub(crate) struct LineTo {}
|
||||
#[allow(non_upper_case_globals, missing_docs)]
|
||||
#[doc = "Std lib function: lineTo"]
|
||||
pub(crate) const LineTo: LineTo = LineTo {};
|
||||
fn boxed_line_to(
|
||||
args: crate::std::Args,
|
||||
) -> std::pin::Pin<
|
||||
Box<
|
||||
dyn std::future::Future<
|
||||
Output = anyhow::Result<crate::executor::MemoryItem, crate::errors::KclError>,
|
||||
>,
|
||||
>,
|
||||
> {
|
||||
Box::pin(line_to(args))
|
||||
}
|
||||
|
||||
impl crate::docs::StdLibFn for LineTo {
|
||||
fn name(&self) -> String {
|
||||
"lineTo".to_string()
|
||||
@ -65,7 +77,7 @@ impl crate::docs::StdLibFn for LineTo {
|
||||
}
|
||||
|
||||
fn std_lib_fn(&self) -> crate::std::StdFn {
|
||||
line_to
|
||||
boxed_line_to
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> Box<dyn crate::docs::StdLibFn> {
|
||||
|
@ -7,6 +7,18 @@ pub(crate) struct Min {}
|
||||
#[allow(non_upper_case_globals, missing_docs)]
|
||||
#[doc = "Std lib function: min"]
|
||||
pub(crate) const Min: Min = Min {};
|
||||
fn boxed_min(
|
||||
args: crate::std::Args,
|
||||
) -> std::pin::Pin<
|
||||
Box<
|
||||
dyn std::future::Future<
|
||||
Output = anyhow::Result<crate::executor::MemoryItem, crate::errors::KclError>,
|
||||
>,
|
||||
>,
|
||||
> {
|
||||
Box::pin(min(args))
|
||||
}
|
||||
|
||||
impl crate::docs::StdLibFn for Min {
|
||||
fn name(&self) -> String {
|
||||
"min".to_string()
|
||||
@ -57,7 +69,7 @@ impl crate::docs::StdLibFn for Min {
|
||||
}
|
||||
|
||||
fn std_lib_fn(&self) -> crate::std::StdFn {
|
||||
min
|
||||
boxed_min
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> Box<dyn crate::docs::StdLibFn> {
|
||||
|
@ -7,6 +7,18 @@ pub(crate) struct Show {}
|
||||
#[allow(non_upper_case_globals, missing_docs)]
|
||||
#[doc = "Std lib function: show"]
|
||||
pub(crate) const Show: Show = Show {};
|
||||
fn boxed_show(
|
||||
args: crate::std::Args,
|
||||
) -> std::pin::Pin<
|
||||
Box<
|
||||
dyn std::future::Future<
|
||||
Output = anyhow::Result<crate::executor::MemoryItem, crate::errors::KclError>,
|
||||
>,
|
||||
>,
|
||||
> {
|
||||
Box::pin(show(args))
|
||||
}
|
||||
|
||||
impl crate::docs::StdLibFn for Show {
|
||||
fn name(&self) -> String {
|
||||
"show".to_string()
|
||||
@ -52,7 +64,7 @@ impl crate::docs::StdLibFn for Show {
|
||||
}
|
||||
|
||||
fn std_lib_fn(&self) -> crate::std::StdFn {
|
||||
show
|
||||
boxed_show
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> Box<dyn crate::docs::StdLibFn> {
|
||||
|
Reference in New Issue
Block a user