Skip to content

Commit 61fbdbb

Browse files
Add Debug implementations for libcollection structs
1 parent a52da95 commit 61fbdbb

File tree

10 files changed

+496
-0
lines changed

10 files changed

+496
-0
lines changed

src/libcollections/binary_heap.rs

+60
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,20 @@ pub struct PeekMut<'a, T: 'a + Ord> {
228228
sift: bool,
229229
}
230230

231+
#[stable(feature = "collection_debug", since = "1.15.0")]
232+
impl<'a, T: Ord> fmt::Debug for PeekMut<'a, T> {
233+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
234+
f.pad("PeekMut { .. }")
235+
}
236+
}
237+
238+
#[stable(feature = "collection_debug", since = "1.15.0")]
239+
impl<'a, T: Ord + fmt::Debug> fmt::Debug for PeekMut<'a, T> {
240+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
241+
f.pad(&format!("PeekMut({:?})", self.heap.data[0]))
242+
}
243+
}
244+
231245
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
232246
impl<'a, T: Ord> Drop for PeekMut<'a, T> {
233247
fn drop(&mut self) {
@@ -968,6 +982,22 @@ pub struct Iter<'a, T: 'a> {
968982
iter: slice::Iter<'a, T>,
969983
}
970984

985+
#[stable(feature = "collection_debug", since = "1.15.0")]
986+
impl<'a, T: 'a> fmt::Debug for Iter<'a, T> {
987+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
988+
f.pad("BinaryHeap::Iter { .. }")
989+
}
990+
}
991+
992+
#[stable(feature = "collection_debug", since = "1.15.0")]
993+
impl<'a, T: 'a + fmt::Debug> fmt::Debug for Iter<'a, T> {
994+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
995+
f.debug_tuple("BinaryHeap::Iter")
996+
.field(&self.iter.as_slice())
997+
.finish()
998+
}
999+
}
1000+
9711001
// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
9721002
#[stable(feature = "rust1", since = "1.0.0")]
9731003
impl<'a, T> Clone for Iter<'a, T> {
@@ -1016,6 +1046,22 @@ pub struct IntoIter<T> {
10161046
iter: vec::IntoIter<T>,
10171047
}
10181048

1049+
#[stable(feature = "collection_debug", since = "1.15.0")]
1050+
impl<T> fmt::Debug for IntoIter<T> {
1051+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1052+
f.pad("BinaryHeap::IntoIter { .. }")
1053+
}
1054+
}
1055+
1056+
#[stable(feature = "collection_debug", since = "1.15.0")]
1057+
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
1058+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1059+
f.debug_tuple("BinaryHeap::IntoIter")
1060+
.field(&self.iter.as_slice())
1061+
.finish()
1062+
}
1063+
}
1064+
10191065
#[stable(feature = "rust1", since = "1.0.0")]
10201066
impl<T> Iterator for IntoIter<T> {
10211067
type Item = T;
@@ -1055,6 +1101,20 @@ pub struct Drain<'a, T: 'a> {
10551101
iter: vec::Drain<'a, T>,
10561102
}
10571103

1104+
#[stable(feature = "collection_debug", since = "1.15.0")]
1105+
impl<'a, T: 'a> fmt::Debug for Drain<'a, T> {
1106+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1107+
f.pad("BinaryHeap::Drain { .. }")
1108+
}
1109+
}
1110+
1111+
#[stable(feature = "collection_debug", since = "1.15.0")]
1112+
impl<'a, T: 'a + fmt::Debug> fmt::Debug for Drain<'a, T> {
1113+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1114+
f.pad(&format!("BinaryHeap::Drain({:?})", self.iter))
1115+
}
1116+
}
1117+
10581118
#[stable(feature = "drain", since = "1.6.0")]
10591119
impl<'a, T: 'a> Iterator for Drain<'a, T> {
10601120
type Item = T;

src/libcollections/btree/map.rs

+120
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,41 @@ pub struct Iter<'a, K: 'a, V: 'a> {
270270
length: usize,
271271
}
272272

273+
#[stable(feature = "collection_debug", since = "1.15.0")]
274+
impl<'a, K: 'a, V: 'a> fmt::Debug for Iter<'a, K, V> {
275+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
276+
f.pad("BTreeMap::Iter { .. }")
277+
}
278+
}
279+
280+
#[stable(feature = "collection_debug", since = "1.15.0")]
281+
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Iter<'a, K, V> {
282+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
283+
f.debug_list().entries(self.clone()).finish()
284+
}
285+
}
286+
273287
/// A mutable iterator over a BTreeMap's entries.
274288
#[stable(feature = "rust1", since = "1.0.0")]
275289
pub struct IterMut<'a, K: 'a, V: 'a> {
276290
range: RangeMut<'a, K, V>,
277291
length: usize,
278292
}
279293

294+
#[stable(feature = "collection_debug", since = "1.15.0")]
295+
impl<'a, K: 'a, V: 'a> fmt::Debug for IterMut<'a, K, V> {
296+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
297+
f.pad("BTreeMap::IterMut { .. }")
298+
}
299+
}
300+
301+
#[stable(feature = "collection_debug", since = "1.15.0")]
302+
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for IterMut<'a, K, V> {
303+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
304+
f.pad(&format!("BTreeMap::IterMut({:?})", self.range))
305+
}
306+
}
307+
280308
/// An owning iterator over a BTreeMap's entries.
281309
#[stable(feature = "rust1", since = "1.0.0")]
282310
pub struct IntoIter<K, V> {
@@ -285,30 +313,104 @@ pub struct IntoIter<K, V> {
285313
length: usize,
286314
}
287315

316+
#[stable(feature = "collection_debug", since = "1.15.0")]
317+
impl<K, V> fmt::Debug for IntoIter<K, V> {
318+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
319+
f.pad("BTreeMap::IntoIter { .. }")
320+
}
321+
}
322+
323+
#[stable(feature = "collection_debug", since = "1.15.0")]
324+
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IntoIter<K, V> {
325+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
326+
let range = Range {
327+
front: self.front.reborrow(),
328+
back: self.back.reborrow(),
329+
};
330+
f.debug_list().entries(range).finish()
331+
}
332+
}
333+
288334
/// An iterator over a BTreeMap's keys.
289335
#[stable(feature = "rust1", since = "1.0.0")]
290336
pub struct Keys<'a, K: 'a, V: 'a> {
291337
inner: Iter<'a, K, V>,
292338
}
293339

340+
#[stable(feature = "collection_debug", since = "1.15.0")]
341+
impl<'a, K: 'a, V: 'a> fmt::Debug for Keys<'a, K, V> {
342+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
343+
f.pad("BTreeMap::Keys { .. }")
344+
}
345+
}
346+
347+
#[stable(feature = "collection_debug", since = "1.15.0")]
348+
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Keys<'a, K, V> {
349+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
350+
f.debug_list().entries(self.inner.clone()).finish()
351+
}
352+
}
353+
294354
/// An iterator over a BTreeMap's values.
295355
#[stable(feature = "rust1", since = "1.0.0")]
296356
pub struct Values<'a, K: 'a, V: 'a> {
297357
inner: Iter<'a, K, V>,
298358
}
299359

360+
#[stable(feature = "collection_debug", since = "1.15.0")]
361+
impl<'a, K: 'a, V: 'a> fmt::Debug for Values<'a, K, V> {
362+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
363+
f.pad("BTreeMap::Values { .. }")
364+
}
365+
}
366+
367+
#[stable(feature = "collection_debug", since = "1.15.0")]
368+
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Values<'a, K, V> {
369+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
370+
f.debug_list().entries(self.inner.clone()).finish()
371+
}
372+
}
373+
300374
/// A mutable iterator over a BTreeMap's values.
301375
#[stable(feature = "map_values_mut", since = "1.10.0")]
302376
pub struct ValuesMut<'a, K: 'a, V: 'a> {
303377
inner: IterMut<'a, K, V>,
304378
}
305379

380+
#[stable(feature = "collection_debug", since = "1.15.0")]
381+
impl<'a, K: 'a, V: 'a> fmt::Debug for ValuesMut<'a, K, V> {
382+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
383+
f.pad("BTreeMap::ValuesMut { .. }")
384+
}
385+
}
386+
387+
#[stable(feature = "collection_debug", since = "1.15.0")]
388+
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for ValuesMut<'a, K, V> {
389+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
390+
f.pad(&format!("BTreeMap::ValuesMut({:?})", self.inner))
391+
}
392+
}
393+
306394
/// An iterator over a sub-range of BTreeMap's entries.
307395
pub struct Range<'a, K: 'a, V: 'a> {
308396
front: Handle<NodeRef<marker::Immut<'a>, K, V, marker::Leaf>, marker::Edge>,
309397
back: Handle<NodeRef<marker::Immut<'a>, K, V, marker::Leaf>, marker::Edge>,
310398
}
311399

400+
#[stable(feature = "collection_debug", since = "1.15.0")]
401+
impl<'a, K: 'a, V: 'a> fmt::Debug for Range<'a, K, V> {
402+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
403+
f.pad("BTreeMap::Range { .. }")
404+
}
405+
}
406+
407+
#[stable(feature = "collection_debug", since = "1.15.0")]
408+
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Range<'a, K, V> {
409+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
410+
f.debug_list().entries(self.clone()).finish()
411+
}
412+
}
413+
312414
/// A mutable iterator over a sub-range of BTreeMap's entries.
313415
pub struct RangeMut<'a, K: 'a, V: 'a> {
314416
front: Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>,
@@ -318,6 +420,24 @@ pub struct RangeMut<'a, K: 'a, V: 'a> {
318420
_marker: PhantomData<&'a mut (K, V)>,
319421
}
320422

423+
#[stable(feature = "collection_debug", since = "1.15.0")]
424+
impl<'a, K: 'a, V: 'a> fmt::Debug for RangeMut<'a, K, V> {
425+
default fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
426+
f.pad("BTreeMap::RangeMut { .. }")
427+
}
428+
}
429+
430+
#[stable(feature = "collection_debug", since = "1.15.0")]
431+
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for RangeMut<'a, K, V> {
432+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
433+
let range = Range {
434+
front: self.front.reborrow(),
435+
back: self.back.reborrow(),
436+
};
437+
f.debug_list().entries(range).finish()
438+
}
439+
}
440+
321441
/// A view into a single entry in a map, which may either be vacant or occupied.
322442
/// This enum is constructed from the [`entry`] method on [`BTreeMap`].
323443
///

0 commit comments

Comments
 (0)