1
use crate::metadata::Metadata;
2

            
3
use super::{Expression, Literal, Name};
4
use serde::{Deserialize, Serialize};
5
use uniplate::derive::Uniplate;
6

            
7
/// A `Factor` is an indivisible expression, such as a literal or a reference.
8
2520
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Uniplate)]
9
#[uniplate()]
10
#[biplate(to=Name)]
11
#[biplate(to=Literal)]
12
#[biplate(to=Metadata)]
13
#[biplate(to=Expression)]
14
pub enum Factor {
15
    Literal(Literal),
16
    Reference(Name),
17
}
18

            
19
impl std::fmt::Display for Factor {
20
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21
        match self {
22
            Factor::Literal(x) => x.fmt(f),
23
            Factor::Reference(x) => x.fmt(f),
24
        }
25
    }
26
}
27

            
28
impl From<Literal> for Factor {
29
    fn from(value: Literal) -> Self {
30
        Factor::Literal(value)
31
    }
32
}
33

            
34
impl From<Name> for Factor {
35
204
    fn from(value: Name) -> Self {
36
204
        Factor::Reference(value)
37
204
    }
38
}