1 #![allow(bare_trait_objects)]
3 pub struct FormatWith<'a, I, F> {
5 /// FormatWith uses interior mutability because Display::fmt takes &self.
6 inner: RefCell<Option<(I, F)>>,
9 use std::cell::RefCell;
14 pub fn new_format<'a, I, F>(iter: I, separator: &'a str, f: F) -> FormatWith<'a, I, F>
17 F: FnMut(I::Item, &mut FnMut(&fmt::Display) -> fmt::Result) -> fmt::Result,
19 FormatWith { sep: separator, inner: RefCell::new(Some((iter, f))) }
23 let _ = new_format(0..32, " | ", |i, f| f(&format_args!("0x{:x}", i)));