diff --git a/src/lib.rs b/src/lib.rs index 9742b7a..12a176f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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"))); + }; +} diff --git a/ttrpc-codegen/src/lib.rs b/ttrpc-codegen/src/lib.rs index e9c7445..57038c5 100644 --- a/ttrpc-codegen/src/lib.rs +++ b/ttrpc-codegen/src/lib.rs @@ -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,