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

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

#7 in #use

Download history 17/week @ 2023-12-24 47/week @ 2023-12-31 26/week @ 2024-01-07 24/week @ 2024-01-14 3/week @ 2024-01-21 11/week @ 2024-02-11 8/week @ 2024-02-18 36/week @ 2024-02-25 21/week @ 2024-03-03 9/week @ 2024-03-10

78 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
~33K SLoC