Skip to content

Commit f7f3c00

Browse files
committed
feat(host): parse signature-inferred host results
1 parent ddfe640 commit f7f3c00

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

pd-host-function/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ fn type_label(ty: &Type) -> Result<String, Error> {
352352
let inner_label = type_label(inner)?;
353353
Ok(format!("{inner_label} | null"))
354354
}
355-
"VmResult" | "BuiltinResult" | "HostResult" => {
355+
"VmResult" | "BuiltinResult" | "HostResult" | "HostCallResult" => {
356356
let syn::PathArguments::AngleBracketed(args) = &segment.arguments else {
357357
return Err(Error::new_spanned(
358358
&segment.arguments,
@@ -472,3 +472,25 @@ fn uses_taken_extractor(ty: &Type) -> bool {
472472
_ => false,
473473
}
474474
}
475+
476+
#[cfg(test)]
477+
mod tests {
478+
use super::expand_pd_host_function;
479+
use syn::{ItemFn, Meta, Token, parse_quote, punctuated::Punctuated};
480+
481+
#[test]
482+
fn accepts_host_call_result_from_the_function_signature() {
483+
let attr: Punctuated<Meta, Token![,]> = parse_quote!(name = "test::suspend");
484+
let item: ItemFn = parse_quote! {
485+
/// Returns a value after a host operation completes.
486+
#[pd_host_function(name = "test::suspend")]
487+
fn suspend() -> VmResult<HostCallResult<Value>> {
488+
todo!()
489+
}
490+
};
491+
492+
let expanded = expand_pd_host_function(attr, item)
493+
.expect("HostCallResult should be accepted from the return signature");
494+
assert!(expanded.to_string().contains("HostCallResult"));
495+
}
496+
}

0 commit comments

Comments
 (0)