devela/code/util/items.rs
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
// devela::code::util::items
//
//! skip formatting macros
//
/// *`s`kip `f`ormatting* wrapper macro.
///
/// Preserves the formatting of the code provided as arguments, by relying on
/// the fact that `rustfmt` does not usually apply formatting inside macros.
///
/// *Rust will format macros only if they use parenthesis `()` and the input is
/// separated by commas, then it formats is the same way as function call.*
///
/// This macro can be used as an alternative to the `#[rustfmt::skip]` attribute,
/// specially in places where it can't be applied yet on stable rust.
///
/// # Examples
/// ```
/// # use devela::sf;
/// // rustfmt has no powers here
/// sf! { println!(); for i in 0..3 { print!{"{i} "} } println!(); }
/// ```
#[macro_export]
#[cfg_attr(cargo_primary_package, doc(hidden))]
macro_rules! sf { ( $($line:tt)+ ) => { $($line)+ }; }
#[doc(inline)]
pub use sf;
/// Groups items together and expands them as if they were written directly.
///
/// It can be useful to apply an attribute to a group of items.
///
/// It can also preserve the formatting of the code provided as arguments,
/// but the [`sf`] macro is better for that, since it works with any arbitrary
/// code sequences like statements, expressions… instead of with just Rust items.
///
/// # Examples
/// ```
/// # use devela::items;
/// #[cfg(feature = "std")]
/// items! {
/// mod something {
/// pub struct SomeThing;
/// }
/// pub use something::SomeThing;
/// }
/// ```
#[macro_export]
#[cfg_attr(cargo_primary_package, doc(hidden))]
macro_rules! items { ( $($item:item)* ) => { $($item)* }; }
#[doc(inline)]
pub use items;