Skip to content

Commit c93f4e2

Browse files
committed
Add macros for include ttrpc gen code
Give macros for more convenient to use, if it is in Default dir Signed-off-by: jokemanfire <[email protected]>
1 parent 4a493e1 commit c93f4e2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/lib.rs

+29
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,32 @@ cfg_async! {
7676
#[doc(hidden)]
7777
pub use asynchronous as r#async;
7878
}
79+
80+
/// Macro to include the mod.rs file from the OUT_DIR.
81+
/// This is only work on out_dir not set and use 'gen_mod' feature.
82+
/// ```rust,ignore
83+
/// mod protocals {
84+
/// include_mod!();
85+
/// }
86+
/// ```
87+
/// [`OUT_DIR`]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
88+
#[macro_export]
89+
macro_rules! include_mod {
90+
() => {
91+
include!(concat!(env!("OUT_DIR"), concat!("/", "mod.rs")));
92+
};
93+
}
94+
95+
/// Macro to include files ending with _ttrpc.rs from the OUT_DIR
96+
/// This is only work on out_dir not set.
97+
/// ```rust,ignore
98+
/// mod protocals {
99+
/// include_ttrpc!("helloworld");
100+
/// }
101+
/// ```
102+
#[macro_export]
103+
macro_rules! include_ttrpc {
104+
($name:expr) => {
105+
include!(concat!(env!("OUT_DIR"), concat!("/", $name, "_ttrpc.rs")));
106+
};
107+
}

ttrpc-codegen/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! ```
2727
//! If there's no out_dir and use 'gen_mod' feature
2828
//! You can use the following method to include the target file
29-
//! include!(concat!(env!("OUT_DIR"), "/mod.rs"));
29+
//! ttrpc::include_mod!();
3030
3131
pub use protobuf_codegen::{
3232
Customize as ProtobufCustomize, CustomizeCallback as ProtobufCustomizeCallback,

0 commit comments

Comments
 (0)