liberty-db 0.1.3

`liberty` data structre
Documentation
use std::fmt;
use strum::IntoEnumIterator;
use crate::HashMap;
use super::{
    BooleanExpressionLike,
    LogicState,LogicVector,
    LogicStateTable,
};

#[derive(Clone,Debug)]
pub struct Port{
    name:  String,
}
impl Port {
    #[inline]
    pub fn new(name: &str) -> Self{
        Self { name: name.to_string() }
    }
    #[inline]
    pub fn to_box(self) -> Box<Self>{
        Box::new(self)
    }
}

impl fmt::Display for Port{
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.name)
    }
}
impl PartialEq for Port {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.name == other.name
    }
}
impl std::cmp::Eq for Port {}
impl std::hash::Hash for Port {
    #[inline]
    fn hash<H: std::hash::Hasher>(&self, hasher: &mut H) {
        self.name.hash(hasher);
    }
}

lazy_static! {
    static ref BASIC_MAP: HashMap<LogicVector, LogicState> = {
        let mut m = HashMap::new();
        for state in LogicState::iter(){
            let _ = m.insert(
                LogicVector::new(vec![state]),
                state,
            );
        }
        m
    };
}

impl BooleanExpressionLike for Port{
    #[inline]
    fn get_state_stable(&self) -> LogicStateTable {
        LogicStateTable::new( 
            BASIC_MAP.clone(), 
            [(self.clone(), 0)]
                                .iter()
                                .cloned()
                                .collect(),
        )
    }
}