1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! The id the game gives each item.
/// An item of the game by the number its item data gives it, as a prop's
/// `UsedItem` names the item the prop was placed from.
///
/// # Examples
///
/// ```
/// use enshwick::ItemId;
///
/// let torch = ItemId::from(1_042);
/// assert_eq!(torch.get(), 1_042);
/// assert_eq!(torch, ItemId::new(1_042));
/// ```
#[derive(
Clone,
Copy,
Debug,
Default,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
serde::Serialize,
serde::Deserialize,
)]
#[serde(transparent)]
pub struct ItemId(u32);
impl ItemId {
/// The item the game numbers `id`, in a `const` too.
///
/// # Examples
///
/// See [`ItemId`].
#[must_use]
pub const fn new(id: u32) -> Self {
Self(id)
}
/// The game's number for the item.
///
/// # Examples
///
/// See [`ItemId`].
#[must_use]
pub const fn get(self) -> u32 {
self.0
}
}
impl From<u32> for ItemId {
fn from(id: u32) -> Self {
Self(id)
}
}
impl From<ItemId> for u32 {
fn from(item: ItemId) -> Self {
item.0
}
}