toasty_core/stmt/
entry_mut.rs1use super::{Expr, Value};
2
3#[derive(Debug)]
4pub enum EntryMut<'a> {
5 Expr(&'a mut Expr),
6 Value(&'a mut Value),
7}
8
9impl EntryMut<'_> {
10 pub fn as_expr(&self) -> &Expr {
11 match self {
12 EntryMut::Expr(e) => e,
13 _ => todo!(),
14 }
15 }
16
17 pub fn as_expr_mut(&mut self) -> &mut Expr {
18 match self {
19 EntryMut::Expr(e) => e,
20 _ => todo!(),
21 }
22 }
23
24 pub fn is_expr(&self) -> bool {
25 matches!(self, EntryMut::Expr(_))
26 }
27
28 pub fn is_statement(&self) -> bool {
29 matches!(self, EntryMut::Expr(e) if e.is_stmt())
30 }
31
32 pub fn is_value(&self) -> bool {
33 matches!(self, EntryMut::Value(_) | EntryMut::Expr(Expr::Value(_)))
34 }
35
36 pub fn is_value_null(&self) -> bool {
37 matches!(
38 self,
39 EntryMut::Value(Value::Null) | EntryMut::Expr(Expr::Value(Value::Null))
40 )
41 }
42
43 pub fn is_default(&self) -> bool {
44 matches!(self, EntryMut::Expr(Expr::Default))
45 }
46
47 pub fn take(&mut self) -> Expr {
48 match self {
49 EntryMut::Expr(expr) => expr.take(),
50 EntryMut::Value(value) => value.take().into(),
51 }
52 }
53
54 pub fn insert(&mut self, expr: Expr) {
55 match self {
56 EntryMut::Expr(e) => **e = expr,
57 EntryMut::Value(e) => match expr {
58 Expr::Value(value) => **e = value,
59 _ => panic!("cannot store expression in value entry"),
60 },
61 }
62 }
63}
64
65impl<'a> From<&'a mut Expr> for EntryMut<'a> {
66 fn from(value: &'a mut Expr) -> Self {
67 EntryMut::Expr(value)
68 }
69}
70
71impl<'a> From<&'a mut Value> for EntryMut<'a> {
72 fn from(value: &'a mut Value) -> Self {
73 EntryMut::Value(value)
74 }
75}