1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::Flush;

/// A wrapper for flush function `for<R> FnMut(*const c_char) -> R`.
///
/// It implements [`Flush`] trait and can be used in conjunction with IntoTryWriteFn trait to simplify type inference.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FlushFn<F, R>(F)
where
    F: FnMut() -> R;

impl<F, R> FlushFn<F, R>
where
    F: FnMut() -> R,
{
    /// Creates a new `FlushFn` containing the given closure or function.
    pub fn new(closure: F) -> Self {
        Self(closure)
    }
}

impl<F, R> Flush for FlushFn<F, R>
where
    F: FnMut() -> R,
{
    type Output = R;
    fn flush(&mut self) -> Self::Output {
        self.0()
    }
}