tuwunel_database/map/
id.rs1use crate::{engine::descriptor::Descriptor, maps::MAPS};
2
3#[derive(Clone, Copy, Debug)]
8pub struct MapId(pub(crate) usize);
9
10#[macro_export]
15macro_rules! map {
16 ($name:expr) => {
17 const { $crate::MapId::named($name) }
18 };
19}
20
21impl MapId {
22 #[must_use]
27 pub const fn named(name: &str) -> Self {
28 let mut index = 0; while index < MAPS.len() {
31 if MAPS[index].name.len() == name.len() && matches(&MAPS[index], name.as_bytes()) {
32 return Self(index);
33 }
34
35 index = index.saturating_add(1);
36 }
37
38 panic!("{}", name);
39 }
40}
41
42const fn matches(desc: &Descriptor, name: &[u8]) -> bool {
43 let mut index = 0; while index < desc.name.len() {
46 if desc.name.as_bytes()[index] != name[index] {
47 return false;
48 }
49
50 index = index.saturating_add(1);
51 }
52
53 true
54}