1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
#![forbid(unsafe_code)]
#![no_std]
//! # `::with_builtin_macros`
//!
//! [](https://github.com/danielhenrymantilla/with_builtin_macros.rs)
//! [](https://crates.io/crates/with_builtin_macros)
//! [](https://docs.rs/with_builtin_macros)
//! [](https://gist.github.com/danielhenrymantilla/8e5b721b3929084562f8f65668920c33)
//! [](https://github.com/rust-secure-code/safety-dance/)
//! [](https://github.com/danielhenrymantilla/with_builtin_macros.rs/blob/master/LICENSE)
//! [](https://github.com/danielhenrymantilla/with_builtin_macros.rs/actions)
//!
//! ### Helper for macro_rules authors to chain their macros with builtin ones (such as `env!`, `include!`, or `concat_idents!`).
pub use ::proc_macros::with_builtin;
/// Documentation for the built-in macros supported by [`with_builtin`!].
pub mod builtin_macros {
/// See [the stdlib documentation][`::core::concat!`].
///
/// # Example
///
/// ```rust
/// use ::with_builtin_macros::with_builtin;
/// macro_rules! expect_hello_world {
/// ("Hello, World!") => ();
/// }
///
/// with_builtin!(let $msg = concat!("Hello, ", "World!") in {
/// expect_hello_world!($msg);
/// });
/// ```
pub mod concat {}
/// See [the stdlib documentation][`::core::concat_idents!`].
///
/// # Example
///
/// ```rust
/// use ::with_builtin_macros::with_builtin;
///
/// with_builtin!(let $fname = concat_idents!(f, o, o) in {
/// fn $fname ()
/// {}
/// });
///
/// foo();
/// ```
pub mod concat_idents {}
/// See [the stdlib documentation][`::core::env!`].
pub mod env {}
/// See [the stdlib documentation][`::core::option_env!`].
///
/// # Example
///
/// ```rust
/// // Objective
/// cfg_env! {
/// #[cfg_env("NON_EXISTENT_ENV_VAR")]
/// compile_error!("Unreachable!");
/// }
/// // Some module to be used when debugging
/// cfg_env! {
/// #[cfg_env("MY_FANCY_NAME_DEBUG")]
/// pub mod debugging_helpers {
/// // ...
/// }
/// }
///
/// // Implementation
/// macro_rules! cfg_env {(
/// #[cfg_env($var_name:expr)]
/// $item:item
/// ) => (
/// ::with_builtin_macros::with_builtin!(let $mb_env = option_env!($var_name) in {
/// cfg_non_empty! {
/// #[cfg_non_empty($mb_env)]
/// $item
/// }
/// });
/// )}
/// use cfg_env;
///
/// // Helper
/// macro_rules! cfg_non_empty {
/// (
/// #[cfg_non_empty()]
/// $item:item
/// ) => (
/// /* Nothing */
/// );
/// (
/// #[cfg_non_empty( $($stuff:tt)+ )]
/// $item:item
/// ) => (
/// $item
/// );
/// }
/// use cfg_non_empty;
/// ```
pub mod option_env {}
/// See [the stdlib documentation][`::core::stringify!`].
pub mod stringify {}
/// See [the stdlib documentation][`::core::include!`].
///
/// The difference between [`::core::include!`] and this version
/// of the macro is that, due to limitations of proc-macros in stable Rust,
/// it is not possible to know whence a macro is called.
///
/// Thus, this macro requires it be called with a path that starts
/// from the "root" of the package, _i.e._, a path that will be interpreted
/// as if it started from: `concat!(env!("CARGO_MANIFEST_DIR"), "/")`.
///
/// # Example
///
/// ```rust
/// # macro_rules! ignore {($($t:tt)*) => ()} ignore! {
/// use ::with_builtin_macros::with_builtin;
///
/// macro_rules! metamancy {(
/// $use_stmt:item
///
/// $macro_def_item:item
///
/// #[cfg(any())]
/// mod to_be_expanded { $foo_fn:item }
///
/// $main_fn:item
///
/// $macro_call:item
/// ) => (
/// $foo_fn
/// )}
///
/// #[cfg(any())]
/// mod to_be_expanded {
/// fn foo ()
/// {}
/// }
///
/// fn main ()
/// {
/// foo();
/// }
///
/// with_builtin!(let $this_file = include_from_root!("src/main.rs") in {
/// metamancy!($this_file);
/// });
/// # } fn main () {}
/// ```
pub mod include_from_root {}
/// See [the stdlib documentation][`::core::include_bytes!`].
///
/// The difference between [`::core::include_bytes!`] and this version
/// of the macro is that, due to limitations of proc-macros in stable Rust,
/// it is not possible to know whence a macro is called.
///
/// Thus, this macro requires it be called with a path that starts
/// from the "root" of the package, _i.e._, a path that will be interpreted
/// as if it started from: `concat!(env!("CARGO_MANIFEST_DIR"), "/")`.
pub mod include_bytes_from_root {}
/// See [the stdlib documentation][`::core::include_str!`].
///
/// The difference between [`::core::include_str!`] and this version
/// of the macro is that, due to limitations of proc-macros in stable Rust,
/// it is not possible to know whence a macro is called.
///
/// Thus, this macro requires it be called with a path that starts
/// from the "root" of the package, _i.e._, a path that will be interpreted
/// as if it started from: `concat!(env!("CARGO_MANIFEST_DIR"), "/")`.
///
/// # Example
///
/// ```rust,ignore
/// use ::with_builtin_macros::with_builtin;
///
/// const HEX_ARRAY: &[u8] = {
/// with_builtin!(let $hex_string = include_str_from_root!("path/to/hex/file") in {
/// ::hex_literal::hex!($hex_string)
/// })
/// };
/// ```
pub mod include_str_from_root {}
}