Skip to main content

datex_core/global/
stack_index.rs

1//! This module contains the definition of the [StackIndex] structure.
2//! The index is used to represent the position of a value in the stack during execution.
3use binrw::{BinRead, BinWrite};
4use core::{fmt::Display, ops::AddAssign};
5
6#[derive(
7    BinRead, BinWrite, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord,
8)]
9#[brw(little)]
10pub struct StackIndex(pub u32);
11
12impl Display for StackIndex {
13    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
14        write!(f, "{{{}}}", self.0)
15    }
16}
17
18impl AddAssign<u32> for StackIndex {
19    fn add_assign(&mut self, rhs: u32) {
20        self.0 += rhs;
21    }
22}