-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macro: pub fn
is not supported
#15
Comments
Woops... that's an oversight! |
The Rust API Guidelines calls this Another point from that checklist that applies here is To fix both, use something like this: macro_rules! fn_macro {
// Allow `fn foo()`
($(#[$attr:meta])* fn $name:ident($arg:ident: $ty:ty) $fun:block) => {
fn_macro!{
internal $(#[$attr])* [] fn $name($arg: $ty) $fun
}
};
// Allow `pub(...) fn foo()`
($(#[$attr:meta])* pub($($vis:tt)+) fn $name:ident($arg:ident: $ty:ty) $fun:block) => {
fn_macro!{
internal $(#[$attr])* [pub($($vis)+)] fn $name($arg: $ty) $fun
}
};
// Allow `pub fn foo()`
($(#[$attr:meta])* pub fn $name:ident($arg:ident: $ty:ty) $fun:block) => {
fn_macro!{
internal $(#[$attr])* [pub] fn $name($arg: $ty) $fun
}
};
(internal $(#[$attr:meta])* [$($vis:tt)*] fn $name:ident($arg:ident: $ty:ty) $fun:block) => {
$(#[$attr])*
$($vis)* fn $name($arg: $ty) $fun
};
}
fn_macro!{
#[cfg(debug_assertions)]
pub(crate) fn foo(bar: i32) {
println!("{}", bar);
}
}
fn main() {
foo(42);
} |
Any chance to have it working out of the box? I also stuck with that issue, cannot use cached. The only solution I see now is to create mirroring function which will be public and will call to internal cached. |
But there is another issue which prevents me to do that:
I am trying to cache the structure method |
To cache a structure method you have to use a workaround like this. The reason is that the |
The macro doesn't let me assign privacy to the function.
The text was updated successfully, but these errors were encountered: