Skip to content

Commit 1f34864

Browse files
committed
fix(macros): Allow macros 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. The same applies to `#[prompt]` as well.
1 parent 9349f5c commit 1f34864

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

crates/rmcp-macros/src/prompt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ pub fn prompt(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream>
108108
}
109109
match &fn_item.sig.output {
110110
syn::ReturnType::Default => {
111-
quote! { -> futures::future::BoxFuture<#lt, ()> }
111+
quote! { -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = ()> + Send + #lt>> }
112112
}
113113
syn::ReturnType::Type(_, ty) => {
114-
quote! { -> futures::future::BoxFuture<#lt, #ty> }
114+
quote! { -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = #ty> + Send + #lt>> }
115115
}
116116
}
117117
})?;

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)