alith_core/
concatenator.rs1#[derive(Clone, PartialEq, Debug, Default)]
2pub enum TextConcatenator {
3 DoubleNewline,
4 #[default]
5 SingleNewline,
6 Space,
7 Comma,
8 Custom(String),
9}
10
11impl TextConcatenator {
12 pub fn as_str(&self) -> &str {
13 match self {
14 TextConcatenator::DoubleNewline => "\n\n",
15 TextConcatenator::SingleNewline => "\n",
16 TextConcatenator::Space => " ",
17 TextConcatenator::Comma => ", ",
18 TextConcatenator::Custom(custom) => custom,
19 }
20 }
21}
22
23pub trait TextConcatenatorTrait {
24 fn concatenator_mut(&mut self) -> &mut TextConcatenator;
25
26 fn clear_built(&self);
27
28 fn concate_deol(&mut self) -> &mut Self {
29 if self.concatenator_mut() != &TextConcatenator::DoubleNewline {
30 *self.concatenator_mut() = TextConcatenator::DoubleNewline;
31 self.clear_built();
32 }
33 self
34 }
35
36 fn concate_seol(&mut self) -> &mut Self {
37 if self.concatenator_mut() != &TextConcatenator::SingleNewline {
38 *self.concatenator_mut() = TextConcatenator::SingleNewline;
39 self.clear_built();
40 }
41 self
42 }
43
44 fn concate_space(&mut self) -> &mut Self {
45 if self.concatenator_mut() != &TextConcatenator::Space {
46 *self.concatenator_mut() = TextConcatenator::Space;
47 self.clear_built();
48 }
49 self
50 }
51
52 fn concate_comma(&mut self) -> &mut Self {
53 if self.concatenator_mut() != &TextConcatenator::Comma {
54 *self.concatenator_mut() = TextConcatenator::Comma;
55 self.clear_built();
56 }
57 self
58 }
59
60 fn concate_custom<T: AsRef<str>>(&mut self, custom: T) -> &mut Self {
61 if self.concatenator_mut() != &TextConcatenator::Custom(custom.as_ref().to_owned()) {
62 *self.concatenator_mut() = TextConcatenator::Custom(custom.as_ref().to_owned());
63 self.clear_built();
64 }
65 self
66 }
67}