1- use std:: { collections:: HashMap , io:: Write } ;
1+ use std:: {
2+ collections:: HashMap ,
3+ io:: { self , Write } ,
4+ } ;
25
36use byteorder:: { BigEndian , WriteBytesExt } ;
47
58use super :: { UnsizedByteArray , MAX_STRING_LENGTH } ;
69
7- fn write_utf_with_len (
8- buf : & mut impl Write ,
9- string : & str ,
10- len : usize ,
11- ) -> Result < ( ) , std:: io:: Error > {
10+ fn write_utf_with_len ( buf : & mut impl Write , string : & str , len : usize ) -> Result < ( ) , io:: Error > {
1211 if string. len ( ) > len {
1312 panic ! (
1413 "String too big (was {} bytes encoded, max {})" ,
@@ -21,21 +20,21 @@ fn write_utf_with_len(
2120}
2221
2322pub trait AzaleaWrite {
24- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > ;
23+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > ;
2524}
2625
2726pub trait AzaleaWriteVar {
28- fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > ;
27+ fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > ;
2928}
3029
3130impl AzaleaWrite for i32 {
32- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
31+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
3332 WriteBytesExt :: write_i32 :: < BigEndian > ( buf, * self )
3433 }
3534}
3635
3736impl AzaleaWriteVar for i32 {
38- fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
37+ fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
3938 let mut buffer = [ 0 ] ;
4039 let mut value = * self ;
4140 if value == 0 {
@@ -54,19 +53,19 @@ impl AzaleaWriteVar for i32 {
5453}
5554
5655impl AzaleaWrite for UnsizedByteArray {
57- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
56+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
5857 buf. write_all ( self )
5958 }
6059}
6160
6261impl < T : AzaleaWrite > AzaleaWrite for Vec < T > {
63- default fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
62+ default fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
6463 self [ ..] . azalea_write ( buf)
6564 }
6665}
6766
6867impl < T : AzaleaWrite > AzaleaWrite for [ T ] {
69- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
68+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
7069 ( self . len ( ) as u32 ) . azalea_write_var ( buf) ?;
7170 for item in self {
7271 T :: azalea_write ( item, buf) ?;
@@ -76,7 +75,7 @@ impl<T: AzaleaWrite> AzaleaWrite for [T] {
7675}
7776
7877impl < K : AzaleaWrite , V : AzaleaWrite > AzaleaWrite for HashMap < K , V > {
79- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
78+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
8079 u32:: azalea_write_var ( & ( self . len ( ) as u32 ) , buf) ?;
8180 for ( key, value) in self {
8281 key. azalea_write ( buf) ?;
@@ -88,7 +87,7 @@ impl<K: AzaleaWrite, V: AzaleaWrite> AzaleaWrite for HashMap<K, V> {
8887}
8988
9089impl < K : AzaleaWrite , V : AzaleaWriteVar > AzaleaWriteVar for HashMap < K , V > {
91- fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
90+ fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
9291 u32:: azalea_write_var ( & ( self . len ( ) as u32 ) , buf) ?;
9392 for ( key, value) in self {
9493 key. azalea_write ( buf) ?;
@@ -100,38 +99,38 @@ impl<K: AzaleaWrite, V: AzaleaWriteVar> AzaleaWriteVar for HashMap<K, V> {
10099}
101100
102101impl AzaleaWrite for Vec < u8 > {
103- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
102+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
104103 ( self . len ( ) as u32 ) . azalea_write_var ( buf) ?;
105104 buf. write_all ( self )
106105 }
107106}
108107
109108impl AzaleaWrite for String {
110- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
109+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
111110 write_utf_with_len ( buf, self , MAX_STRING_LENGTH . into ( ) )
112111 }
113112}
114113
115114impl AzaleaWrite for & str {
116- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
115+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
117116 write_utf_with_len ( buf, self , MAX_STRING_LENGTH . into ( ) )
118117 }
119118}
120119
121120impl AzaleaWrite for u32 {
122- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
121+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
123122 i32:: azalea_write ( & ( * self as i32 ) , buf)
124123 }
125124}
126125
127126impl AzaleaWriteVar for u32 {
128- fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
127+ fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
129128 i32:: azalea_write_var ( & ( * self as i32 ) , buf)
130129 }
131130}
132131
133132impl AzaleaWriteVar for i64 {
134- fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
133+ fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
135134 let mut buffer = [ 0 ] ;
136135 let mut value = * self ;
137136 if value == 0 {
@@ -150,25 +149,25 @@ impl AzaleaWriteVar for i64 {
150149}
151150
152151impl AzaleaWriteVar for u64 {
153- fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
152+ fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
154153 i64:: azalea_write_var ( & ( * self as i64 ) , buf)
155154 }
156155}
157156
158157impl AzaleaWrite for u16 {
159- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
158+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
160159 i16:: azalea_write ( & ( * self as i16 ) , buf)
161160 }
162161}
163162
164163impl AzaleaWriteVar for u16 {
165- fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
164+ fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
166165 i32:: azalea_write_var ( & ( * self as i32 ) , buf)
167166 }
168167}
169168
170169impl < T : AzaleaWriteVar > AzaleaWriteVar for Vec < T > {
171- fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
170+ fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
172171 u32:: azalea_write_var ( & ( self . len ( ) as u32 ) , buf) ?;
173172 for i in self {
174173 i. azalea_write_var ( buf) ?;
@@ -178,56 +177,56 @@ impl<T: AzaleaWriteVar> AzaleaWriteVar for Vec<T> {
178177}
179178
180179impl AzaleaWrite for u8 {
181- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
180+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
182181 WriteBytesExt :: write_u8 ( buf, * self )
183182 }
184183}
185184
186185impl AzaleaWrite for i16 {
187- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
186+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
188187 WriteBytesExt :: write_i16 :: < BigEndian > ( buf, * self )
189188 }
190189}
191190
192191impl AzaleaWrite for i64 {
193- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
192+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
194193 WriteBytesExt :: write_i64 :: < BigEndian > ( buf, * self )
195194 }
196195}
197196
198197impl AzaleaWrite for u64 {
199- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
198+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
200199 i64:: azalea_write ( & ( * self as i64 ) , buf)
201200 }
202201}
203202
204203impl AzaleaWrite for bool {
205- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
204+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
206205 let byte = u8:: from ( * self ) ;
207206 byte. azalea_write ( buf)
208207 }
209208}
210209
211210impl AzaleaWrite for i8 {
212- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
211+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
213212 ( * self as u8 ) . azalea_write ( buf)
214213 }
215214}
216215
217216impl AzaleaWrite for f32 {
218- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
217+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
219218 WriteBytesExt :: write_f32 :: < BigEndian > ( buf, * self )
220219 }
221220}
222221
223222impl AzaleaWrite for f64 {
224- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
223+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
225224 WriteBytesExt :: write_f64 :: < BigEndian > ( buf, * self )
226225 }
227226}
228227
229228impl < T : AzaleaWrite > AzaleaWrite for Option < T > {
230- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
229+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
231230 if let Some ( s) = self {
232231 true . azalea_write ( buf) ?;
233232 s. azalea_write ( buf) ?;
@@ -239,7 +238,7 @@ impl<T: AzaleaWrite> AzaleaWrite for Option<T> {
239238}
240239
241240impl < T : AzaleaWriteVar > AzaleaWriteVar for Option < T > {
242- fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
241+ fn azalea_write_var ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
243242 if let Some ( s) = self {
244243 true . azalea_write ( buf) ?;
245244 s. azalea_write_var ( buf) ?;
@@ -252,7 +251,7 @@ impl<T: AzaleaWriteVar> AzaleaWriteVar for Option<T> {
252251
253252// [T; N]
254253impl < T : AzaleaWrite , const N : usize > AzaleaWrite for [ T ; N ] {
255- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
254+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
256255 for i in self {
257256 i. azalea_write ( buf) ?;
258257 }
@@ -261,23 +260,23 @@ impl<T: AzaleaWrite, const N: usize> AzaleaWrite for [T; N] {
261260}
262261
263262impl AzaleaWrite for simdnbt:: owned:: NbtTag {
264- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
263+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
265264 let mut data = Vec :: new ( ) ;
266265 self . write ( & mut data) ;
267266 buf. write_all ( & data)
268267 }
269268}
270269
271270impl AzaleaWrite for simdnbt:: owned:: NbtCompound {
272- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
271+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
273272 let mut data = Vec :: new ( ) ;
274273 simdnbt:: owned:: NbtTag :: Compound ( self . clone ( ) ) . write ( & mut data) ;
275274 buf. write_all ( & data)
276275 }
277276}
278277
279278impl AzaleaWrite for simdnbt:: owned:: Nbt {
280- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
279+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
281280 let mut data = Vec :: new ( ) ;
282281 self . write_unnamed ( & mut data) ;
283282 buf. write_all ( & data)
@@ -288,7 +287,14 @@ impl<T> AzaleaWrite for Box<T>
288287where
289288 T : AzaleaWrite ,
290289{
291- fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , std :: io:: Error > {
290+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
292291 T :: azalea_write ( & * * self , buf)
293292 }
294293}
294+
295+ impl < A : AzaleaWrite , B : AzaleaWrite > AzaleaWrite for ( A , B ) {
296+ fn azalea_write ( & self , buf : & mut impl Write ) -> Result < ( ) , io:: Error > {
297+ self . 0 . azalea_write ( buf) ?;
298+ self . 1 . azalea_write ( buf)
299+ }
300+ }
0 commit comments