X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Flogger.rs;h=dbca9b785e85dfbaf3c68253e7e47b91225c6bdc;hb=a61746246c369dada11469c25dd739f4807c042b;hp=aac83f42a3c2f82a5520fc380f4006ca345288e2;hpb=2223e92ac6b1ef0b11ac7448ed35f5d0adf77aaa;p=rust-lightning diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs index aac83f42..dbca9b78 100644 --- a/lightning/src/util/logger.rs +++ b/lightning/src/util/logger.rs @@ -169,6 +169,26 @@ impl<'a> core::fmt::Display for DebugBytes<'a> { } } +/// Wrapper for logging `Iterator`s. +/// +/// This is not exported to bindings users as fmt can't be used in C +#[doc(hidden)] +pub struct DebugIter + Clone>(pub I); +impl + Clone> fmt::Display for DebugIter { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(f, "[")?; + let mut iter = self.0.clone(); + if let Some(item) = iter.next() { + write!(f, "{}", item)?; + } + while let Some(item) = iter.next() { + write!(f, ", {}", item)?; + } + write!(f, "]")?; + Ok(()) + } +} + #[cfg(test)] mod tests { use crate::util::logger::{Logger, Level};