code_gen/expression/
with_params.rs1use crate::{CodeBuffer, Expression, Literal};
2
3pub trait WithParams: Sized {
5 fn params(&self) -> &[Box<dyn Expression>];
7
8 fn add_boxed_param(&mut self, param: Box<dyn Expression>);
10
11 fn with_boxed_param(mut self, param: Box<dyn Expression>) -> Self {
13 self.add_boxed_param(param);
14 self
15 }
16
17 fn add_param<E>(&mut self, param: E)
19 where
20 E: 'static + Expression,
21 {
22 self.add_boxed_param(Box::new(param));
23 }
24
25 fn with_param<E>(mut self, param: E) -> Self
27 where
28 E: 'static + Expression,
29 {
30 self.add_param(param);
31 self
32 }
33
34 fn add_literal_param<L>(&mut self, literal: L)
36 where
37 L: Into<Literal>,
38 {
39 self.add_param(literal.into());
40 }
41
42 fn with_literal_param<L>(self, literal: L) -> Self
44 where
45 L: Into<Literal>,
46 {
47 self.with_param(literal.into())
48 }
49
50 fn write_params(&self, b: &mut CodeBuffer) {
52 if let Some((first, rest)) = self.params().split_first() {
53 first.write(b);
54 for param in rest {
55 b.write(", ");
56 param.write(b);
57 }
58 }
59 }
60
61 fn write_params_with_parens(&self, b: &mut CodeBuffer) {
63 b.write("(");
64 self.write_params(b);
65 b.write(")");
66 }
67}