Skip to content

Commit 7944dbe

Browse files
committed
allow specifying assosiated functions with Any derive
1 parent 871bd23 commit 7944dbe

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

crates/rune-macros/src/any.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ pub(crate) fn expand_install_with(
155155
}
156156

157157
installers.extend(attr.protocols.iter().map(|protocol| protocol.expand()));
158+
installers.extend(attr.functions.iter().map(|function| quote_spanned!{function.span()=>
159+
module.function_meta(#function)?;
160+
}));
158161

159162
if let Some(install_with) = &attr.install_with {
160163
installers.push(quote_spanned! { input.span() =>

crates/rune-macros/src/context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pub(crate) struct TypeAttr {
7474
pub(crate) item: Option<syn::Path>,
7575
/// Protocols to "derive"
7676
pub(crate) protocols: Vec<TypeProtocol>,
77+
/// Assosiated functions
78+
pub(crate) functions: Vec<syn::Path>,
7779
/// Parsed documentation.
7880
pub(crate) docs: Vec<syn::Expr>,
7981
}
@@ -503,6 +505,12 @@ impl Context {
503505
syn::parenthesized!(protocols in meta.input);
504506
attr.protocols
505507
.extend(protocols.parse_terminated(TypeProtocol::parse, Token![,])?);
508+
} else if meta.path == FUNCTIONS {
509+
// Parse `#[rune(functions(<function>,*))]`
510+
let functions;
511+
syn::parenthesized!(functions in meta.input);
512+
attr.functions
513+
.extend(functions.parse_terminated(syn::Path::parse, Token![,])?);
506514
} else {
507515
return Err(syn::Error::new_spanned(
508516
&meta.path,

crates/rune-macros/src/internals.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub const ITEM: Symbol = Symbol("item");
2020
pub const MODULE: Symbol = Symbol("module");
2121
pub const INSTALL_WITH: Symbol = Symbol("install_with");
2222
pub const PROTOCOLS: Symbol = Symbol("protocols");
23+
pub const FUNCTIONS: Symbol = Symbol("functions");
2324

2425
pub const CONSTRUCTOR: Symbol = Symbol("constructor");
2526
pub const GET: Symbol = Symbol("get");

0 commit comments

Comments
 (0)