aboutsummaryrefslogtreecommitdiffstats
path: root/src/yaml/write.rs
blob: a1e52a5299b4dc2ab47ba512d0e9e5ce766fd4ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pub struct IoAdapter<'a, T: std::io::Write> {
    inner: &'a mut T,
}

impl<'a, T: std::io::Write> IoAdapter<'a, T> {
    pub fn new(writer: &'a mut T) -> Self {
        IoAdapter { inner: writer }
    }
}

impl<T: std::io::Write> std::fmt::Write for IoAdapter<'_, T> {
    fn write_str(&mut self, s: &str) -> std::fmt::Result {
        match self.inner.write_all(s.as_bytes()) {
            Ok(()) => Ok(()),
            Err(_) => Err(std::fmt::Error),
        }
    }
}