Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macros for include ttrpc gen code #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
/// ```rust,ignore
/// mod protocals {
/// include_ttrpc!("helloworld");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how to include helloworld.rs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I think is that this macro only provides the code for *_ttrpc.rs generated by ttrpc-code gen The generated proto's rs code is not within the scope of this macro.

/// }
/// ```
#[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
Loading