use super::logical::LogicalOp;
use num::{BigInt, BigUint};
use std::fmt::{Debug, Display, Formatter, self};
pub const MAX_SMALL_BITS: u8 = 128;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct Bit(pub bool);
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Bitwise {
op: LogicalOp,
bits: u16
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct SmallBits(u8);
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum BinaryDisplay {
Bin,
Oct,
Dec,
Hex
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Binary {
bits: SmallBits,
display: BinaryDisplay,
value: u128
}
#[derive(Clone, Eq, PartialEq, Hash)]
pub struct Natural(pub BigUint, pub BinaryDisplay);
impl Debug for Natural {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
<Self as Display>::fmt(self, fmt)
}
}
impl Display for Natural {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
use BinaryDisplay::*;
match self.1 {
Bin => write!(fmt, "{:#b}", self.0),
Oct => write!(fmt, "{:#o}", self.0),
Dec => write!(fmt, "{}", self.0),
Hex => write!(fmt, "{:#x}", self.0)
}
}
}
#[derive(Clone, Eq, PartialEq, Hash)]
pub struct Integer(pub BigInt, pub BinaryDisplay);
impl Debug for Integer {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
<Self as Display>::fmt(self, fmt)
}
}
impl Display for Integer {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
use BinaryDisplay::*;
match self.1 {
Bin => write!(fmt, "{:#b}", self.0),
Oct => write!(fmt, "{:#o}", self.0),
Dec => write!(fmt, "{}", self.0),
Hex => write!(fmt, "{:#x}", self.0)
}
}
}