Skip to content

Commit

Permalink
Add macros for include ttrpc gen code
Browse files Browse the repository at this point in the history
Give macros for more convenient to use, if it is in Default dir

Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
  • Loading branch information
jokemanfire committed Jan 6, 2025
1 parent 4a493e1 commit 7417ea4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,32 @@ cfg_async! {
#[doc(hidden)]
pub use asynchronous as r#async;
}

/// Macro to include the mod.rs file from the OUT_DIR
/// This is only work on out_dir not set and use 'gen_mod' feature
/// ```rust,ignore
/// mod protocals {
/// include_mod!();
/// }
/// ```
/// [`OUT_DIR`]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
#[macro_export]
macro_rules! include_mod {
() => {
include!(concat!(env!("OUT_DIR"), concat!("/", "mod.rs")));
};
}

/// Macro to include files ending with _ttrpc.rs from the OUT_DIR
/// This is only work on out_dir not set and use 'gen_mod' feature
/// ```rust,ignore
/// mod protocals {
/// include_ttrpc!("helloworld");
/// }
/// ```
#[macro_export]
macro_rules! include_ttrpc {
($name:expr) => {
include!(concat!(env!("OUT_DIR"), concat!("/", $name, "_ttrpc.rs")));
};
}
2 changes: 1 addition & 1 deletion ttrpc-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//! ```
//! If there's no out_dir and use 'gen_mod' feature
//! You can use the following method to include the target file
//! include!(concat!(env!("OUT_DIR"), "/mod.rs"));
//! ttrpc::include_mod!();
pub use protobuf_codegen::{
Customize as ProtobufCustomize, CustomizeCallback as ProtobufCustomizeCallback,
Expand Down

0 comments on commit 7417ea4

Please sign in to comment.