1
use crate::metadata::Metadata;
2

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

            
7
/// An `Atom` 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 Atom {
15
    Literal(Literal),
16
    Reference(Name),
17
}
18

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

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

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