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
29
30
use crate::statements::Statement;
use crate::CodeBuffer;

/// Represents a linked statement.
pub struct LinkedStatement {
    statements: Vec<Box<dyn Statement>>,
}

impl Default for LinkedStatement {
    fn default() -> Self {
        Self {
            statements: Vec::with_capacity(8),
        }
    }
}

impl LinkedStatement {
    //! Link

    /// Links the statement.
    pub fn link(&mut self, statement: Box<dyn Statement>) {
        self.statements.push(statement);
    }
}

impl Statement for LinkedStatement {
    fn write(&self, b: &mut CodeBuffer, level: usize) {
        self.statements.iter().for_each(|s| s.write(b, level));
    }
}