@@ -5,8 +5,10 @@ use serde::{Deserialize, Serialize};
5
5
/// An enchantment attached to an item.
6
6
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
7
7
pub struct Enchantment {
8
+ /// The type of the enchantment.
8
9
#[ serde( rename = "id" ) ]
9
10
kind : EnchantmentKind ,
11
+ /// Enchantment level, represented by an `i8` for vanilla compatibility
10
12
#[ serde( rename = "lvl" ) ]
11
13
level : i8 ,
12
14
}
@@ -21,6 +23,8 @@ impl Enchantment {
21
23
///
22
24
/// The level is capped at `i8::MAX` for compatability
23
25
/// with Vanilla.
26
+ #[ must_use]
27
+ #[ allow( clippy:: cast_possible_truncation) ]
24
28
pub fn new ( kind : EnchantmentKind , level : u32 ) -> Self {
25
29
Self {
26
30
kind,
@@ -29,11 +33,14 @@ impl Enchantment {
29
33
}
30
34
31
35
/// Gets the kind of this enchantment.
32
- pub fn kind ( & self ) -> EnchantmentKind {
36
+ #[ must_use]
37
+ pub const fn kind ( & self ) -> EnchantmentKind {
33
38
self . kind
34
39
}
35
40
36
41
/// Gets the level of this enchantment.
42
+ #[ must_use]
43
+ #[ allow( clippy:: cast_sign_loss) ]
37
44
pub fn level ( & self ) -> u32 {
38
45
self . level . max ( 0 ) as u32
39
46
}
@@ -48,6 +55,7 @@ impl Enchantment {
48
55
/// Sets the level of this enchantment.
49
56
///
50
57
/// The level is capped to `i8::MAX`.
58
+ #[ allow( clippy:: cast_possible_truncation) ]
51
59
pub fn set_level ( & mut self , level : u32 ) {
52
60
self . level = level. min ( i8:: MAX as u32 ) as i8 ;
53
61
}
0 commit comments