terra_items_xbox360/
slot.rs1use crate::{Item, Prefix};
2use terra_types::PositiveI16;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub struct ItemSlot {
6 pub item: Item,
7 pub prefix: Option<Prefix>,
8 pub count: PositiveI16,
9}
10
11impl From<SingleItemSlot> for ItemSlot {
12 fn from(value: SingleItemSlot) -> Self {
13 ItemSlot {
14 item: value.item,
15 prefix: value.prefix,
16 count: PositiveI16::new(1).expect("In bounds"),
17 }
18 }
19}
20
21#[cfg(feature = "convert")]
22impl TryFrom<terra_items::ItemSlot> for ItemSlot {
23 type Error = ();
24 fn try_from(value: terra_items::ItemSlot) -> Result<Self, ()> {
25 Ok(Self {
26 item: value.item.try_into()?,
27 prefix: value.prefix.and_then(|x| x.try_into().ok()),
28 count: PositiveI16::new(value.count.get().min(i16::MAX as i32) as i16)
29 .expect("Same min bound"),
30 })
31 }
32}
33
34#[cfg(feature = "convert")]
35impl TryFrom<ItemSlot> for terra_items::ItemSlot {
36 type Error = ();
37 fn try_from(value: ItemSlot) -> Result<Self, ()> {
38 Ok(Self {
39 item: value.item.try_into()?,
40 prefix: value.prefix.map(|x| x.into()),
41 count: terra_types::PositiveI32::new(value.count.get() as i32).expect("Same min bound"),
42 })
43 }
44}
45
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
47pub struct SingleItemSlot {
48 pub item: Item,
49 pub prefix: Option<Prefix>,
50}
51
52impl From<ItemSlot> for SingleItemSlot {
53 fn from(item_slot: ItemSlot) -> Self {
54 SingleItemSlot {
55 item: item_slot.item,
56 prefix: item_slot.prefix,
57 }
58 }
59}
60
61#[cfg(feature = "convert")]
62impl TryFrom<terra_items::SingleItemSlot> for SingleItemSlot {
63 type Error = ();
64 fn try_from(value: terra_items::SingleItemSlot) -> Result<Self, ()> {
65 Ok(Self {
66 item: value.item.try_into()?,
67 prefix: value.prefix.and_then(|x| x.try_into().ok()),
68 })
69 }
70}
71
72#[cfg(feature = "convert")]
73impl TryFrom<SingleItemSlot> for terra_items::SingleItemSlot {
74 type Error = ();
75 fn try_from(value: SingleItemSlot) -> Result<Self, ()> {
76 Ok(Self {
77 item: value.item.try_into()?,
78 prefix: value.prefix.map(|x| x.into()),
79 })
80 }
81}