gloss_utils/
macros.rs

1// https://rustwasm.github.io/docs/book/game-of-life/debugging.html
2// A macro to provide `println!(..)`-style syntax for `console.log` logging.
3// #[cfg(target_arch = "wasm32")]
4#[allow(unused_macros)]
5#[macro_export]
6macro_rules! log {
7    ( $( $t:tt )* ) => {
8        #[cfg(target_arch = "wasm32")]
9        web_sys::console::log_1(&format!( $( $t )* ).into());
10    }
11}
12
13// https://stackoverflow.com/questions/59984712/rust-macro-to-convert-between-identical-enums
14#[allow(unused_macros)]
15#[macro_export]
16macro_rules! convert_enum_from{($src: ident, $dst: ident, $($variant: ident,)*)=> {
17    impl From<$src> for $dst {
18        fn from(src: $src) -> Self {
19            match src {
20                $($src::$variant => Self::$variant,)*
21            }
22        }
23    }
24}}
25#[allow(unused_macros)]
26#[macro_export]
27macro_rules! convert_enum_into{($src: ident, $dst: ident, $($variant: ident,)*)=> {
28    impl Into<$dst> for $src {
29        fn into(self) -> $dst {
30            match self {
31                $(Self::$variant => $dst::$variant,)*
32            }
33        }
34    }
35}}