4
4
use crate :: serialize:: writer:: WriteExt ;
5
5
use std:: io;
6
6
7
+ macro_rules! debug_assert_has_capacity {
8
+ ( $writer: expr) => {
9
+ debug_assert!( $writer. has_capacity( 4 ) )
10
+ } ;
11
+ }
12
+
7
13
pub trait Formatter {
8
14
#[ inline]
9
15
fn write_null < W > ( & mut self , writer : & mut W ) -> io:: Result < ( ) >
@@ -196,7 +202,7 @@ pub trait Formatter {
196
202
where
197
203
W : ?Sized + io:: Write + WriteExt ,
198
204
{
199
- reserve_minimum ! ( writer) ;
205
+ debug_assert_has_capacity ! ( writer) ;
200
206
unsafe { writer. write_reserved_punctuation ( b']' ) . unwrap ( ) } ;
201
207
Ok ( ( ) )
202
208
}
@@ -206,7 +212,7 @@ pub trait Formatter {
206
212
where
207
213
W : ?Sized + io:: Write + WriteExt ,
208
214
{
209
- reserve_minimum ! ( writer) ;
215
+ debug_assert_has_capacity ! ( writer) ;
210
216
if !first {
211
217
unsafe { writer. write_reserved_punctuation ( b',' ) . unwrap ( ) }
212
218
}
@@ -238,7 +244,7 @@ pub trait Formatter {
238
244
where
239
245
W : ?Sized + io:: Write + WriteExt ,
240
246
{
241
- reserve_minimum ! ( writer) ;
247
+ debug_assert_has_capacity ! ( writer) ;
242
248
unsafe {
243
249
writer. write_reserved_punctuation ( b'}' ) . unwrap ( ) ;
244
250
}
@@ -250,7 +256,7 @@ pub trait Formatter {
250
256
where
251
257
W : ?Sized + io:: Write + WriteExt ,
252
258
{
253
- reserve_minimum ! ( writer) ;
259
+ debug_assert_has_capacity ! ( writer) ;
254
260
if !first {
255
261
unsafe {
256
262
writer. write_reserved_punctuation ( b',' ) . unwrap ( ) ;
@@ -272,7 +278,7 @@ pub trait Formatter {
272
278
where
273
279
W : ?Sized + io:: Write + WriteExt ,
274
280
{
275
- reserve_minimum ! ( writer) ;
281
+ debug_assert_has_capacity ! ( writer) ;
276
282
unsafe { writer. write_reserved_punctuation ( b':' ) }
277
283
}
278
284
0 commit comments