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.
///
/// This is not exported to bindings users as fmt can't be used in C
#[doc(hidden)]
///
/// 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> {
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;
- 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() {
- for item in iter.deref_mut() {
+ while let Some(item) = iter.next() {
write!(f, ", {}", item)?;
}
write!(f, "]")?;
write!(f, ", {}", item)?;
}
write!(f, "]")?;
macro_rules! log_iter {
($obj: expr) => {
macro_rules! log_iter {
($obj: expr) => {
- $crate::util::logger::DebugIter(core::cell::RefCell::new($obj))
+ $crate::util::logger::DebugIter($obj)