Prettier tree printing

master
Mark 2024-03-04 15:49:07 -08:00
parent 37fc1f1974
commit a0ffc73333
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
1 changed files with 17 additions and 8 deletions

View File

@ -1,4 +1,7 @@
use std::{fmt::Display, num::NonZeroU8};
use std::{
fmt::{Debug, Display},
num::NonZeroU8,
};
use termion::color::{self, Color};
@ -34,7 +37,7 @@ impl Display for Player {
}
}
#[derive(PartialEq, Eq, Clone, Copy)]
#[derive(PartialEq, Eq, Clone, Copy, Hash)]
pub enum Symb {
Number(NonZeroU8),
Zero,
@ -47,13 +50,19 @@ pub enum Symb {
impl Display for Symb {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Number(x) => x.fmt(f),
Self::Zero => '0'.fmt(f),
Self::Plus => '+'.fmt(f),
Self::Minus => '-'.fmt(f),
Self::Div => '÷'.fmt(f),
Self::Times => '×'.fmt(f),
Self::Number(x) => write!(f, "{x}")?,
Self::Zero => write!(f, "0")?,
Self::Plus => write!(f, "+")?,
Self::Minus => write!(f, "-")?,
Self::Div => write!(f, "÷")?,
Self::Times => write!(f, "×")?,
}
Ok(())
}
}
impl Debug for Symb {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Display::fmt(self, f)
}
}