use super::Signature;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Variable {
pub(crate) sig: Signature,
pub(crate) id: usize,
}
impl Variable {
pub fn name(&self) -> Option<String> {
self.sig.sig.read().expect("poisoned signature").variables[self.id].clone()
}
pub fn display(&self) -> String {
if let Some(ref name) = self.sig.sig.read().expect("poisoned signature").variables[self.id]
{
format!("{}_", name)
} else {
format!("var{}_", self.id)
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Operator {
pub(crate) sig: Signature,
pub(crate) id: usize,
}
impl Operator {
pub fn arity(&self) -> u32 {
self.sig.sig.read().expect("poisoned signature").operators[self.id].0
}
pub fn name(&self) -> Option<String> {
self.sig.sig.read().expect("poisoned signature").operators[self.id]
.1
.clone()
}
pub fn display(&self) -> String {
if let (_, Some(ref name)) =
self.sig.sig.read().expect("poisoned signature").operators[self.id]
{
name.clone()
} else {
format!("op{}", self.id)
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Atom {
Variable(Variable),
Operator(Operator),
}
impl Atom {
pub fn display(&self) -> String {
match *self {
Atom::Variable(ref v) => v.display(),
Atom::Operator(ref o) => o.display(),
}
}
}
impl From<Variable> for Atom {
fn from(var: Variable) -> Atom {
Atom::Variable(var)
}
}
impl From<Operator> for Atom {
fn from(op: Operator) -> Atom {
Atom::Operator(op)
}
}