soroban_tools/utils/
impl.rs

1/*
2    Copyright (c) 2023-2024 Frederic Kyung-jin Rezeau (오경진 吳景振)
3
4    This file is part of soroban-kit.
5
6    Licensed under the MIT License, this software is provided "AS IS",
7    no liability assumed. For details, see the LICENSE file in the
8    root directory.
9
10    Author: Fred Kyung-jin Rezeau <fred@litemint.com>
11*/
12
13// Note: C-style enums only, does not support reflection for
14// enum variants with data.
15#[macro_export]
16macro_rules! reflective_enum {
17    ( $name:ident { $( $variant:ident ),* $(,)? } ) => {
18        #[contracttype]
19        #[derive(Clone, Copy, Debug, PartialEq, Eq)]
20        pub enum $name {
21            $($variant),+
22        }
23
24        impl $name {
25            pub fn get_values(env: &Env) -> soroban_sdk::Vec<$name> {
26                vec![env, $($name::$variant),+]
27            }
28        }
29    };
30}