vortex_gpu_kernels/
indent.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::io::Write;
5use std::{fmt, io};
6
7pub struct IndentedWriter<W: Write> {
8    write: W,
9    indent: String,
10}
11
12impl<W: Write> IndentedWriter<W> {
13    pub fn new(write: W) -> Self {
14        Self {
15            write,
16            indent: "".to_string(),
17        }
18    }
19
20    pub fn indent<F>(&mut self, indented: F) -> io::Result<()>
21    where
22        F: FnOnce(&mut IndentedWriter<W>) -> io::Result<()>,
23    {
24        let original_ident = self.indent.clone();
25        self.indent += "    ";
26        let res = indented(self);
27        self.indent = original_ident;
28        res
29    }
30
31    pub fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
32        write!(self.write, "{}{}", self.indent, fmt)
33    }
34}