1use crate::ValType;
2
3#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5pub enum IndexType {
6 I32,
8 I64,
10}
11
12impl IndexType {
13 pub fn ty(&self) -> ValType {
15 match self {
16 IndexType::I32 => ValType::I32,
17 IndexType::I64 => ValType::I64,
18 }
19 }
20
21 pub fn is_64(&self) -> bool {
23 matches!(self, Self::I64)
24 }
25
26 pub fn max_size(&self) -> u128 {
28 const WASM32_MAX_SIZE: u128 = 1 << 32;
29 const WASM64_MAX_SIZE: u128 = 1 << 64;
30 match self {
31 Self::I32 => WASM32_MAX_SIZE,
32 Self::I64 => WASM64_MAX_SIZE,
33 }
34 }
35
36 pub fn min(&self, other: &Self) -> Self {
38 match (self, other) {
39 (IndexType::I64, IndexType::I64) => IndexType::I64,
40 _ => IndexType::I32,
41 }
42 }
43}