Skip to main content

wowlab_engine_domain/rotation/buffer/
ids.rs

1//! Typed `repr(transparent)` newtypes for a descriptor's stable id and a byte offset.
2
3use derive_more::{Display, From, Into};
4
5/// Stable identifier for a [`super::FieldDescriptor`] in the [`super::DescriptorTable`]: its index.
6#[derive(Clone, Copy, Debug, Display, Eq, From, Hash, Into, Ord, PartialEq, PartialOrd)]
7#[display("{_0}")]
8#[repr(transparent)]
9pub struct DescriptorId(u16);
10
11impl DescriptorId {
12    #[inline]
13    #[must_use]
14    pub const fn new(id: u16) -> Self {
15        Self(id)
16    }
17
18    #[inline]
19    #[must_use]
20    pub const fn get(self) -> u16 {
21        self.0
22    }
23
24    #[inline]
25    #[must_use]
26    pub const fn as_usize(&self) -> usize {
27        self.0 as usize
28    }
29}
30
31/// A byte offset into the dense rotation buffer.
32#[derive(Clone, Copy, Debug, Display, Eq, From, Hash, Into, Ord, PartialEq, PartialOrd)]
33#[display("{_0}")]
34#[repr(transparent)]
35pub struct ByteOffset(usize);
36
37impl ByteOffset {
38    #[inline]
39    #[must_use]
40    pub const fn new(offset: usize) -> Self {
41        Self(offset)
42    }
43
44    #[inline]
45    #[must_use]
46    pub const fn as_usize(&self) -> usize {
47        self.0
48    }
49}