burn_compute/
id.rs

1#[macro_export(local_inner_macros)]
2/// Create a new storage ID type.
3macro_rules! storage_id_type {
4    ($name:ident) => {
5        #[derive(Clone, Hash, PartialEq, Eq)]
6        /// Storage ID.
7        pub struct $name {
8            id: alloc::sync::Arc<alloc::string::String>,
9        }
10
11        impl $name {
12            /// Create a new ID.
13            pub fn new() -> Self {
14                Self {
15                    id: alloc::sync::Arc::new(burn_common::id::IdGenerator::generate()),
16                }
17            }
18        }
19
20        impl Default for $name {
21            fn default() -> Self {
22                Self::new()
23            }
24        }
25    };
26}
27
28#[macro_export(local_inner_macros)]
29/// Create a new memory ID type.
30macro_rules! memory_id_type {
31    ($name:ident) => {
32        #[derive(Clone, Hash, PartialEq, Eq, Debug)]
33        /// Memory ID.
34        pub struct $name {
35            id: alloc::sync::Arc<alloc::string::String>,
36        }
37
38        impl $name {
39            /// Create a new ID.
40            pub(crate) fn new() -> Self {
41                Self {
42                    id: alloc::sync::Arc::new(burn_common::id::IdGenerator::generate()),
43                }
44            }
45        }
46
47        impl Default for $name {
48            fn default() -> Self {
49                Self::new()
50            }
51        }
52    };
53}