bevy_retro_macros/lib.rs
1//! Macros used in Bevy Retro
2
3/// Utility to implement deref for single-element tuple structs
4///
5/// This is particularly useful when you need to create a Bevy
6///
7/// # Example
8///
9/// ```no-test
10/// # use bevy_retro_macros::impl_deref;
11///
12/// #[derive(Component)]
13/// struct Score(usize);
14///
15/// impl_deref!(Score, usize);
16/// ```
17#[macro_export]
18macro_rules! impl_deref {
19 ($struct:ident, $target:path) => {
20 impl std::ops::Deref for $struct {
21 type Target = $target;
22
23 fn deref(&self) -> &Self::Target {
24 &self.0
25 }
26 }
27
28 impl std::ops::DerefMut for $struct {
29 fn deref_mut(&mut self) -> &mut Self::Target {
30 &mut self.0
31 }
32 }
33 };
34}
35
36/// Utility macro for adding an attribute to a batch of items
37///
38/// # Example
39///
40/// ```
41/// # use bevy_retro_macros::items_attr;
42/// // Only import these libraries for wasm targets
43/// items_attr!(cfg(wasm), {
44/// use web_sys;
45/// use js_sys;
46/// });
47/// ```
48#[macro_export]
49macro_rules! items_attr {
50 ($attr:ident($meta:meta), {
51 $(
52 $item:item
53 )*
54 }) => {
55 $(
56 #[$attr($meta)]
57 $item
58 )*
59 };
60}