#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use std::cmp::Ordering;
use std::fmt;
use std::fmt::Formatter;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct Wire {
pub index: u32,
}
impl Wire {
pub const ONE: Wire = Wire { index: 0 };
}
impl Ord for Wire {
fn cmp(&self, other: &Self) -> Ordering {
if *self == Wire::ONE && *other == Wire::ONE {
Ordering::Equal
} else if *self == Wire::ONE {
Ordering::Greater
} else if *other == Wire::ONE {
Ordering::Less
} else {
self.index.cmp(&other.index)
}
}
}
impl PartialOrd for Wire {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl fmt::Display for Wire {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
if self.index == 0 {
write!(f, "1")
} else {
write!(f, "wire_{}", self.index)
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct BooleanWire {
pub wire: Wire,
}
impl BooleanWire {
pub fn new_unsafe(wire: Wire) -> Self {
BooleanWire { wire }
}
pub fn wire(self) -> Wire {
self.wire
}
}
#[derive(Clone, Debug)]
pub struct BinaryWire {
pub bits: Vec<BooleanWire>,
}
#[allow(clippy::len_without_is_empty)]
impl BinaryWire {
pub fn len(&self) -> usize {
self.bits.len()
}
}