Drop use of RefCell in DebugIter
[rust-lightning] / lightning / src / util / logger.rs
index 722a81f7ab665b15961363a1f064377718e36dd3..dbca9b785e85dfbaf3c68253e7e47b91225c6bdc 100644 (file)
@@ -173,18 +173,15 @@ impl<'a> core::fmt::Display for DebugBytes<'a> {
 ///
 /// This is not exported to bindings users as fmt can't be used in C
 #[doc(hidden)]
-pub struct DebugIter<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone>(pub core::cell::RefCell<I>);
+pub struct DebugIter<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone>(pub I);
 impl<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone> fmt::Display for DebugIter<T, I> {
        fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
-               use core::ops::DerefMut;
                write!(f, "[")?;
-               let iter_ref = self.0.clone();
-               let mut iter = iter_ref.borrow_mut();
-               for item in iter.deref_mut() {
+               let mut iter = self.0.clone();
+               if let Some(item) = iter.next() {
                        write!(f, "{}", item)?;
-                       break;
                }
-               for item in iter.deref_mut() {
+               while let Some(item) = iter.next() {
                        write!(f, ", {}", item)?;
                }
                write!(f, "]")?;