custom_print/flush_fn.rs
1use crate::Flush;
2
3/// A wrapper for flush function `for<R> FnMut(*const c_char) -> R`.
4///
5/// It implements [`Flush`] trait and can be used in conjunction with IntoTryWriteFn trait to simplify type inference.
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub struct FlushFn<F, R>(F)
8where
9 F: FnMut() -> R;
10
11impl<F, R> FlushFn<F, R>
12where
13 F: FnMut() -> R,
14{
15 /// Creates a new `FlushFn` containing the given closure or function.
16 pub fn new(closure: F) -> Self {
17 Self(closure)
18 }
19}
20
21impl<F, R> Flush for FlushFn<F, R>
22where
23 F: FnMut() -> R,
24{
25 type Output = R;
26 fn flush(&mut self) -> Self::Output {
27 self.0()
28 }
29}