Skip to content

Commit 9b614f4

Browse files
committed
Drop use of RefCell in DebugIter
The `RefCell` was necessary in a previous iteration of the code in which the iterator was not `Clone` so we needed interior mutability in order to consume the iterator. Now that it is `Clone`, we can drop it, as we're no longer mutating the original iterator.
1 parent ba8af22 commit 9b614f4

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

lightning/src/util/logger.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,15 @@ impl<'a> core::fmt::Display for DebugBytes<'a> {
173173
///
174174
/// This is not exported to bindings users as fmt can't be used in C
175175
#[doc(hidden)]
176-
pub struct DebugIter<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone>(pub core::cell::RefCell<I>);
176+
pub struct DebugIter<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone>(pub I);
177177
impl<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone> fmt::Display for DebugIter<T, I> {
178178
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
179-
use core::ops::DerefMut;
180179
write!(f, "[")?;
181-
let iter_ref = self.0.clone();
182-
let mut iter = iter_ref.borrow_mut();
183-
for item in iter.deref_mut() {
180+
let mut iter = self.0.clone();
181+
if let Some(item) = iter.next() {
184182
write!(f, "{}", item)?;
185-
break;
186183
}
187-
for item in iter.deref_mut() {
184+
while let Some(item) = iter.next() {
188185
write!(f, ", {}", item)?;
189186
}
190187
write!(f, "]")?;

lightning/src/util/macro_logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::util::logger::DebugBytes;
1919

2020
macro_rules! log_iter {
2121
($obj: expr) => {
22-
$crate::util::logger::DebugIter(core::cell::RefCell::new($obj))
22+
$crate::util::logger::DebugIter($obj)
2323
}
2424
}
2525

0 commit comments

Comments
 (0)