@@ -73,7 +73,7 @@ pub fn debug_struct_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>, name: &str)
73
73
impl < ' a , ' b : ' a > DebugStruct < ' a , ' b > {
74
74
/// Adds a new field to the generated struct output.
75
75
#[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
76
- pub fn field ( mut self , name : & str , value : & fmt:: Debug ) -> DebugStruct < ' a , ' b > {
76
+ pub fn field ( & mut self , name : & str , value : & fmt:: Debug ) -> & mut DebugStruct < ' a , ' b > {
77
77
self . result = self . result . and_then ( |_| {
78
78
let prefix = if self . has_fields {
79
79
","
@@ -93,10 +93,9 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
93
93
self
94
94
}
95
95
96
- /// Consumes the `DebugStruct`, finishing output and returning any error
97
- /// encountered.
96
+ /// Finishes output and returns any error encountered.
98
97
#[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
99
- pub fn finish ( mut self ) -> fmt:: Result {
98
+ pub fn finish ( & mut self ) -> fmt:: Result {
100
99
if self . has_fields {
101
100
self . result = self . result . and_then ( |_| {
102
101
if self . is_pretty ( ) {
@@ -136,7 +135,7 @@ pub fn debug_tuple_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>, name: &str) -> D
136
135
impl < ' a , ' b : ' a > DebugTuple < ' a , ' b > {
137
136
/// Adds a new field to the generated tuple struct output.
138
137
#[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
139
- pub fn field ( mut self , value : & fmt:: Debug ) -> DebugTuple < ' a , ' b > {
138
+ pub fn field ( & mut self , value : & fmt:: Debug ) -> & mut DebugTuple < ' a , ' b > {
140
139
self . result = self . result . and_then ( |_| {
141
140
let ( prefix, space) = if self . has_fields {
142
141
( "," , " " )
@@ -156,10 +155,9 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
156
155
self
157
156
}
158
157
159
- /// Consumes the `DebugTuple`, finishing output and returning any error
160
- /// encountered.
158
+ /// Finishes output and returns any error encountered.
161
159
#[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
162
- pub fn finish ( mut self ) -> fmt:: Result {
160
+ pub fn finish ( & mut self ) -> fmt:: Result {
163
161
if self . has_fields {
164
162
self . result = self . result . and_then ( |_| {
165
163
if self . is_pretty ( ) {
@@ -231,15 +229,24 @@ pub fn debug_set_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugSet<'a, 'b
231
229
impl < ' a , ' b : ' a > DebugSet < ' a , ' b > {
232
230
/// Adds a new entry to the set output.
233
231
#[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
234
- pub fn entry ( mut self , entry : & fmt:: Debug ) -> DebugSet < ' a , ' b > {
232
+ pub fn entry ( & mut self , entry : & fmt:: Debug ) -> & mut DebugSet < ' a , ' b > {
235
233
self . inner . entry ( entry) ;
236
234
self
237
235
}
238
236
239
- /// Consumes the `DebugSet`, finishing output and returning any error
240
- /// encountered.
237
+ /// Adds the contents of an iterator of entries to the set output.
241
238
#[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
242
- pub fn finish ( mut self ) -> fmt:: Result {
239
+ pub fn entries < D , I > ( & mut self , entries : I ) -> & mut DebugSet < ' a , ' b >
240
+ where D : fmt:: Debug , I : IntoIterator < Item =D > {
241
+ for entry in entries {
242
+ self . entry ( & entry) ;
243
+ }
244
+ self
245
+ }
246
+
247
+ /// Finishes output and returns any error encountered.
248
+ #[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
249
+ pub fn finish ( & mut self ) -> fmt:: Result {
243
250
self . inner . finish ( ) ;
244
251
self . inner . result . and_then ( |_| self . inner . fmt . write_str ( "}" ) )
245
252
}
@@ -265,17 +272,26 @@ pub fn debug_list_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugList<'a,
265
272
}
266
273
267
274
impl < ' a , ' b : ' a > DebugList < ' a , ' b > {
268
- /// Adds a new entry to the set output.
275
+ /// Adds a new entry to the list output.
269
276
#[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
270
- pub fn entry ( mut self , entry : & fmt:: Debug ) -> DebugList < ' a , ' b > {
277
+ pub fn entry ( & mut self , entry : & fmt:: Debug ) -> & mut DebugList < ' a , ' b > {
271
278
self . inner . entry ( entry) ;
272
279
self
273
280
}
274
281
275
- /// Consumes the `DebugSet`, finishing output and returning any error
276
- /// encountered.
282
+ /// Adds the contents of an iterator of entries to the list output.
283
+ #[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
284
+ pub fn entries < D , I > ( & mut self , entries : I ) -> & mut DebugList < ' a , ' b >
285
+ where D : fmt:: Debug , I : IntoIterator < Item =D > {
286
+ for entry in entries {
287
+ self . entry ( & entry) ;
288
+ }
289
+ self
290
+ }
291
+
292
+ /// Finishes output and returns any error encountered.
277
293
#[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
278
- pub fn finish ( mut self ) -> fmt:: Result {
294
+ pub fn finish ( & mut self ) -> fmt:: Result {
279
295
self . inner . finish ( ) ;
280
296
self . inner . result . and_then ( |_| self . inner . fmt . write_str ( "]" ) )
281
297
}
@@ -303,7 +319,7 @@ pub fn debug_map_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugMap<'a, 'b
303
319
impl < ' a , ' b : ' a > DebugMap < ' a , ' b > {
304
320
/// Adds a new entry to the map output.
305
321
#[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
306
- pub fn entry ( mut self , key : & fmt:: Debug , value : & fmt:: Debug ) -> DebugMap < ' a , ' b > {
322
+ pub fn entry ( & mut self , key : & fmt:: Debug , value : & fmt:: Debug ) -> & mut DebugMap < ' a , ' b > {
307
323
self . result = self . result . and_then ( |_| {
308
324
if self . is_pretty ( ) {
309
325
let mut writer = PadAdapter :: new ( self . fmt ) ;
@@ -319,10 +335,19 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
319
335
self
320
336
}
321
337
322
- /// Consumes the `DebugMap`, finishing output and returning any error
323
- /// encountered.
338
+ /// Adds the contents of an iterator of entries to the map output.
339
+ #[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
340
+ pub fn entries < K , V , I > ( & mut self , entries : I ) -> & mut DebugMap < ' a , ' b >
341
+ where K : fmt:: Debug , V : fmt:: Debug , I : IntoIterator < Item =( K , V ) > {
342
+ for ( k, v) in entries {
343
+ self . entry ( & k, & v) ;
344
+ }
345
+ self
346
+ }
347
+
348
+ /// Finishes output and returns any error encountered.
324
349
#[ unstable( feature = "debug_builders" , reason = "method was just created" ) ]
325
- pub fn finish ( self ) -> fmt:: Result {
350
+ pub fn finish ( & mut self ) -> fmt:: Result {
326
351
let prefix = if self . is_pretty ( ) && self . has_fields { "\n " } else { "" } ;
327
352
self . result . and_then ( |_| write ! ( self . fmt, "{}}}" , prefix) )
328
353
}
0 commit comments