#attributes #proc-macro-attributes #pub #mod #proc-macro

macro retrieve

#[{pub_}mod_{pub_}use(a,b,c,...)] => {pub }mod a; {pub }use a::*; and also b,c,

6 stable releases

1.1.2 May 11, 2022
1.1.1 May 2, 2022
1.1.0 Apr 30, 2022
1.0.2 Apr 27, 2022

#19 in #pub

44 downloads per month
Used in 3 crates

MIT license

12KB
168 lines

githubcrates-iodocs-rs
Build Status

retrieve

mod x and use x::* pattern syntax sugar of the proc-macro attribute.

  • retrieve::
    • mod_use => mod x; use x::*; for a module internal.
    • pub_mod_use => pub mod x; use x::* for a public nested modules.
    • mod_pub_use => mod x; pub use x::* for a public flatten modules with separated source writting.
    • pub_mod_pub_use => pub x; pub use x::x for a public nested modules with flatten alias in the root.

I am tired of writing the mod x; use x::*; pattern over and over again for structured beatiful source code!😝 And I like the stylish attribute proc-macro style syntax sugars.💖

Example: examples/

  • src/
    • main.rs
    • x.rs ; Or it can move to x/mod.rs if you like module-name/mod.rs style.
    • x/
      • a.rs ; crate::x::a::*
      • b.rs ; crate::x::b::*
  1. main.rs:
use retrieve::*;

#[mod_pub_use(x)] // <-- here!; it's the same as `mod x; pub use x::*;`
fn main()
{
 // `X` from x::X
 let x = X {
  a: 1,
  b: 2
 };

 // And it from '2. x.rs'; `.a()` from the trait of `x::a::A` and `.b()` from the trait of `x::b::B`
 println!("{:?}", x.a() + x.b());
}
  1. x.rs:
use retrieve::*;

#[mod_pub_use(a, b)] // <-- here!; it's the same as `mod a; pub use a::*;` and `mod b; pub use b::*;`
pub struct X
{
 pub a: i32,
 pub b: i32
}

for Debuggin

retrieve has print feature. It will be show a part of evaluated syntax:

eg. Run the example with print feature:

cargo run --example work_arround --features print

Then, you will get something like it in the build messages:

   Compiling retrieve v1.0.1 (C:\Users\usagi\tmp\retrieve)
[(proc-macro)retrieve::mod_pub_use+print]
mod x; pub use x::*;
fn main()
{ let x = X :: new(1) ; println! ("{:?} {:?}", x.a(), x.to_string()) ; }
[(proc-macro)retrieve::mod_pub_use+print]
mod a; pub use a::*;
mod new; pub use new::*;
mod _impl_already_traits; pub use _impl_already_traits::*;
pub struct X { a : i32 }
[(proc-macro)retrieve::mod_pub_use+print]
mod display; pub use display::*;
use super :: X ;
    Finished dev [unoptimized + debuginfo] target(s) in 1.41s
     Running `target\debug\examples\work_arround.exe`
1 "One!"

LICENSE

Author

Dependencies

~1.5MB
~36K SLoC