@@ -8,7 +8,7 @@ use jiff::Zoned;
88use serde:: { Deserialize , Serialize } ;
99use std:: borrow:: Cow ;
1010use std:: collections:: VecDeque ;
11- use std:: num:: NonZeroUsize ;
11+ use std:: num:: NonZeroU16 ;
1212use std:: sync:: Arc ;
1313use strum:: EnumIs ;
1414use uuid:: Uuid ;
@@ -38,16 +38,16 @@ impl Chat {
3838pub struct ChatHistory {
3939 #[ cfg_attr( feature = "typescript" , ts( as = "Vec<ChatMessage>" ) ) ]
4040 queue : VecDeque < ChatMessage > ,
41- size : NonZeroUsize ,
41+ size : NonZeroU16 ,
4242}
4343
4444impl ChatHistory {
45- pub const MIN : NonZeroUsize = NonZeroUsize :: new ( 100 ) . unwrap ( ) ;
46- pub const MAX : NonZeroUsize = NonZeroUsize :: new ( 500 ) . unwrap ( ) ;
45+ pub const MIN : NonZeroU16 = NonZeroU16 :: new ( 100 ) . unwrap ( ) ;
46+ pub const MAX : NonZeroU16 = NonZeroU16 :: new ( 500 ) . unwrap ( ) ;
4747
48- const fn new ( size : usize ) -> Self {
48+ const fn new ( size : u16 ) -> Self {
4949 let size = size. clamp ( Self :: MIN . get ( ) , Self :: MAX . get ( ) ) ;
50- let size = unsafe { NonZeroUsize :: new_unchecked ( size) } ;
50+ let size = unsafe { NonZeroU16 :: new_unchecked ( size) } ;
5151 Self { queue : VecDeque :: new ( ) , size }
5252 }
5353
@@ -57,8 +57,8 @@ impl ChatHistory {
5757 }
5858
5959 fn prune ( & mut self ) {
60- let size = self . size . get ( ) ;
6160 let len = self . queue . len ( ) ;
61+ let size = usize:: from ( self . size . get ( ) ) ;
6262 if len >= size {
6363 self . queue . drain ( ..=( len - size) ) ;
6464 }
@@ -144,19 +144,19 @@ pub enum ChatMessageAuthor {
144144 #[ default]
145145 System ,
146146 Player {
147- id : PlayerId ,
147+ player : PlayerId ,
148148 } ,
149149}
150150
151151impl From < PlayerId > for ChatMessageAuthor {
152152 fn from ( id : PlayerId ) -> Self {
153- Self :: Player { id }
153+ Self :: Player { player : id }
154154 }
155155}
156156
157157impl From < & PlayerId > for ChatMessageAuthor {
158158 fn from ( id : & PlayerId ) -> Self {
159- Self :: Player { id : id. clone ( ) }
159+ Self :: Player { player : id. clone ( ) }
160160 }
161161}
162162
0 commit comments