public templates do not seem to be usable in the same crate
I would have expected this to work...
pub use derive_deftly;
mod define_wobbling {
use derive_deftly::define_derive_deftly;
define_derive_deftly! {
pub Wobbling =
impl $ttype {
pub fn wobble(&self) -> String {
"wobble wobble".to_string()
}
}
}
}
#[cfg(test)]
mod tests {
use derive_deftly::Deftly;
#[derive(Deftly)]
#[derive_deftly(Wobbling)]
struct Nonesuch {
}
#[test]
fn will_it_wobble() {
let n = Nonesuch {};
assert_eq!(&n.wobble(), "wobble wobble");
}
}
But when I try to build it (with tests), Rust complains:
error: cannot find macro `derive_deftly_template_Wobbling` in this scope
--> src/lib.rs:20:21
|
20 | #[derive_deftly(Wobbling)]
| ^^^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?
help: consider importing this macro through its public re-export
|
17 + use crate::derive_deftly_template_Wobbling;
I'm confused, because I had expected that my use of pub
above would have put the template macro into module scope, where the tests
module should have found it. But it I add the crate::derive_deftly_template_Wobbling
line that Rust suggests, I get:
error: cannot determine resolution for the import
--> src/lib.rs:18:9
|
18 | use crate::derive_deftly_template_Wobbling;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
--> src/lib.rs:18:9
|
18 | use crate::derive_deftly_template_Wobbling;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #52234 <https://github.com/rust-lang/rust/issues/52234>
So I'm a bit stumped.
As a workaround I am not explicitly re-exporting the template macro via "pub use".