luaparser/nodes/statements/
if_statement.rs

1use crate::nodes::{
2    Block,
3    Expression,
4    Statement,
5};
6
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct IfBranch {
9    pub condition: Expression,
10    pub block: Block,
11}
12
13impl From<(Expression, Block)> for IfBranch {
14    fn from((condition, block): (Expression, Block)) -> Self {
15        Self {
16            condition,
17            block,
18        }
19    }
20}
21
22#[derive(Clone, Debug, PartialEq, Eq)]
23pub struct IfStatement {
24    pub branches: Vec<IfBranch>,
25    pub else_block: Option<Block>,
26}
27
28impl From<(Vec<(Expression, Block)>, Option<Block>)> for IfStatement {
29    fn from((branches, else_block): (Vec<(Expression, Block)>, Option<Block>)) -> Self {
30        Self {
31            branches: branches.into_iter().map(IfBranch::from).collect(),
32            else_block,
33        }
34    }
35}
36
37impl Into<Statement> for IfStatement {
38    fn into(self) -> Statement {
39        Statement::If(self)
40    }
41}