1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::{Expression, Builder};
use std::fmt::{Display, Formatter, Result};
#[derive(Debug)]
pub struct While {
condition: Expression,
then: Builder,
}
impl While {
pub fn new(condition: Expression) -> Self {
Self {
condition,
then: Builder::new(),
}
}
pub fn then(&mut self, then: Builder) -> &mut Self {
self.then = then;
self
}
}
impl Display for While {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "while ({}) {{\n{}\n}}", self.condition, self.then)
}
}