Skip to main content

rustidy_print/
output.rs

1//! Print output
2
3// Imports
4use arcstr::Substr;
5
6/// Print output
7#[derive(Debug)]
8pub enum PrintOutput {
9	/// Empty string
10	Empty,
11
12	/// Input range
13	Input(Substr),
14
15	/// String
16	String(String),
17}
18
19impl PrintOutput {
20	/// Mutates this output into a string
21	pub fn make_string(&mut self) -> &mut String {
22		match self {
23			Self::Empty => *self = Self::String(String::new()),
24			Self::Input(s) => {
25				let s = s.as_str().to_owned();
26				*self = Self::String(s);
27			},
28			Self::String(_) => (),
29		}
30
31		match self {
32			Self::String(s) => s,
33			_ => unreachable!()
34		}
35	}
36
37	/// Gets the output as a string
38	#[must_use]
39	pub fn as_str(&self) -> &str {
40		match self {
41			Self::Empty => "",
42			Self::Input(s) => s,
43			Self::String(s) => s,
44		}
45	}
46}