oo_bindgen/backend/dotnet/
formatting.rs1use crate::backend::*;
2
3struct DocumentationPrinter<'a> {
4 inner: &'a mut dyn Printer,
5}
6
7impl<'a> DocumentationPrinter<'a> {
8 fn new(printer: &'a mut dyn Printer) -> Self {
9 Self { inner: printer }
10 }
11}
12
13impl Printer for DocumentationPrinter<'_> {
14 fn write(&mut self, s: &str) -> FormattingResult<()> {
15 self.inner.write(s)
16 }
17
18 fn newline(&mut self) -> FormattingResult<()> {
19 self.inner.newline()?;
20 self.inner.write("/// ")
21 }
22}
23
24pub(crate) fn documentation<F, T>(f: &mut dyn Printer, cb: F) -> FormattingResult<T>
25where
26 F: FnOnce(&mut dyn Printer) -> FormattingResult<T>,
27{
28 let mut printer = DocumentationPrinter::new(f);
29 cb(&mut printer)
30}
31
32pub(crate) fn namespaced<F, T>(f: &mut dyn Printer, namespace: &str, cb: F) -> FormattingResult<T>
33where
34 F: FnOnce(&mut dyn Printer) -> FormattingResult<T>,
35{
36 f.writeln(&format!("namespace {namespace}"))?;
37 blocked(f, |f| cb(f))
38}