Skip to content

Commit

Permalink
allow specifying assosiated functions with Any derive
Browse files Browse the repository at this point in the history
  • Loading branch information
ModProg committed Jul 26, 2023
1 parent 871bd23 commit ba7e74d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/rune-macros/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ pub(crate) fn expand_install_with(
}

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

if let Some(install_with) = &attr.install_with {
installers.push(quote_spanned! { input.span() =>
Expand Down
8 changes: 8 additions & 0 deletions crates/rune-macros/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub(crate) struct TypeAttr {
pub(crate) item: Option<syn::Path>,
/// Protocols to "derive"
pub(crate) protocols: Vec<TypeProtocol>,
/// Assosiated functions
pub(crate) functions: Vec<syn::Path>,
/// Parsed documentation.
pub(crate) docs: Vec<syn::Expr>,
}
Expand Down Expand Up @@ -503,6 +505,12 @@ impl Context {
syn::parenthesized!(protocols in meta.input);
attr.protocols
.extend(protocols.parse_terminated(TypeProtocol::parse, Token![,])?);
} else if meta.path == FUNCTIONS {
// Parse `#[rune(functions(<function>,*))]`
let functions;
syn::parenthesized!(functions in meta.input);
attr.functions
.extend(functions.parse_terminated(syn::Path::parse, Token![,])?);
} else {
return Err(syn::Error::new_spanned(
&meta.path,
Expand Down
1 change: 1 addition & 0 deletions crates/rune-macros/src/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub const ITEM: Symbol = Symbol("item");
pub const MODULE: Symbol = Symbol("module");
pub const INSTALL_WITH: Symbol = Symbol("install_with");
pub const PROTOCOLS: Symbol = Symbol("protocols");
pub const FUNCTIONS: Symbol = Symbol("functions");

pub const CONSTRUCTOR: Symbol = Symbol("constructor");
pub const GET: Symbol = Symbol("get");
Expand Down

0 comments on commit ba7e74d

Please sign in to comment.