File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,29 @@ impl<'a> core::fmt::Display for DebugBytes<'a> {
169
169
}
170
170
}
171
171
172
+ /// Wrapper for logging `Iterator`s.
173
+ ///
174
+ /// This is not exported to bindings users as fmt can't be used in C
175
+ #[ doc( hidden) ]
176
+ pub struct DebugIter < T : fmt:: Display , I : core:: iter:: Iterator < Item = T > + Clone > ( pub core:: cell:: RefCell < I > ) ;
177
+ impl < T : fmt:: Display , I : core:: iter:: Iterator < Item = T > + Clone > fmt:: Display for DebugIter < T , I > {
178
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
179
+ use core:: ops:: DerefMut ;
180
+ write ! ( f, "[" ) ?;
181
+ let iter_ref = self . 0 . clone ( ) ;
182
+ let mut iter = iter_ref. borrow_mut ( ) ;
183
+ for item in iter. deref_mut ( ) {
184
+ write ! ( f, "{}" , item) ?;
185
+ break ;
186
+ }
187
+ for item in iter. deref_mut ( ) {
188
+ write ! ( f, ", {}" , item) ?;
189
+ }
190
+ write ! ( f, "]" ) ?;
191
+ Ok ( ( ) )
192
+ }
193
+ }
194
+
172
195
#[ cfg( test) ]
173
196
mod tests {
174
197
use crate :: util:: logger:: { Logger , Level } ;
Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ use crate::routing::router::Route;
17
17
use crate :: ln:: chan_utils:: HTLCClaim ;
18
18
use crate :: util:: logger:: DebugBytes ;
19
19
20
+ macro_rules! log_iter {
21
+ ( $obj: expr) => {
22
+ $crate:: util:: logger:: DebugIter ( core:: cell:: RefCell :: new( $obj) )
23
+ }
24
+ }
25
+
20
26
/// Logs a pubkey in hex format.
21
27
#[ macro_export]
22
28
macro_rules! log_pubkey {
You can’t perform that action at this time.
0 commit comments