Crates.io | retrieve |
lib.rs | retrieve |
version | 1.1.2 |
source | src |
created_at | 2022-04-27 17:46:36.817778 |
updated_at | 2022-05-11 10:00:13.401336 |
description | #[{pub_}mod_{pub_}use(a,b,c,...)] => {pub }mod a; {pub }use a::*; and also b,c,... |
homepage | |
repository | https://github.com/usagi/retrieve |
max_upload_size | |
id | 576140 |
size | 20,699 |
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.💖
crate::x::a::*
crate::x::b::*
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());
}
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
}
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!"