use std::fmt::Display;
pub trait NodeFormat<ID, T> {
fn format_node(&self, id: &ID, value: &T) -> String;
}
pub struct IDFormatter {}
impl IDFormatter {
pub fn new() -> Self {
Self {}
}
}
impl Default for IDFormatter {
fn default() -> Self {
Self::new()
}
}
impl<ID, T> NodeFormat<ID, T> for IDFormatter
where
ID: Display,
{
fn format_node(&self, id: &ID, _: &T) -> String {
format!("({})", id)
}
}
pub struct ValueFormatter {}
impl ValueFormatter {
pub fn new() -> Self {
Self {}
}
}
impl Default for ValueFormatter {
fn default() -> Self {
Self::new()
}
}
impl<ID, T> NodeFormat<ID, T> for ValueFormatter
where
T: Display,
{
fn format_node(&self, _: &ID, value: &T) -> String {
format!("({})", value)
}
}