Skip to content

Commit e701044

Browse files
committed
fix(macros): Allow #[tool] to work even if Future is not in scope
`#[tool]` generates code that uses Future by name for async functions. This means that consumers have to import Future. This commit fixes that by changing the macro expansion to use std::future::Future instead.
1 parent 9349f5c commit e701044

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

crates/rmcp-macros/src/tool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
234234
// modify the the input function
235235
if fn_item.sig.asyncness.is_some() {
236236
// 1. remove asyncness from sig
237-
// 2. make return type: `std::pin::Pin<Box<dyn Future<Output = #ReturnType> + Send + '_>>`
237+
// 2. make return type: `std::pin::Pin<Box<dyn std::future::Future<Output = #ReturnType> + Send + '_>>`
238238
// 3. make body: { Box::pin(async move { #body }) }
239239
let new_output = syn::parse2::<ReturnType>({
240240
let mut lt = quote! { 'static };
@@ -249,10 +249,10 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
249249
}
250250
match &fn_item.sig.output {
251251
syn::ReturnType::Default => {
252-
quote! { -> futures::future::BoxFuture<#lt, ()> }
252+
quote! { -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + Send + #lt>> }
253253
}
254254
syn::ReturnType::Type(_, ty) => {
255-
quote! { -> futures::future::BoxFuture<#lt, #ty> }
255+
quote! { -> std::pin::Pin<Box<dyn std::future::Future<Output = #ty> + Send + #lt>> }
256256
}
257257
}
258258
})?;

0 commit comments

Comments
 (0)