rustc_ast_pretty/
helpers.rs

1use std::borrow::Cow;
2
3use crate::pp::Printer;
4
5impl Printer {
6    pub fn word_space<W: Into<Cow<'static, str>>>(&mut self, w: W) {
7        self.word(w);
8        self.space();
9    }
10
11    pub fn popen(&mut self) {
12        self.word("(");
13    }
14
15    pub fn pclose(&mut self) {
16        self.word(")");
17    }
18
19    pub fn hardbreak_if_not_bol(&mut self) {
20        if !self.is_beginning_of_line() {
21            self.hardbreak()
22        }
23    }
24
25    pub fn space_if_not_bol(&mut self) {
26        if !self.is_beginning_of_line() {
27            self.space();
28        }
29    }
30
31    pub fn nbsp(&mut self) {
32        self.word(" ")
33    }
34
35    pub fn word_nbsp<S: Into<Cow<'static, str>>>(&mut self, w: S) {
36        self.word(w);
37        self.nbsp()
38    }
39
40    /// Synthesizes a comment that was not textually present in the original
41    /// source file.
42    pub fn synth_comment(&mut self, text: impl Into<Cow<'static, str>>) {
43        self.word("/*");
44        self.space();
45        self.word(text);
46        self.space();
47        self.word("*/")
48    }
49}