use cursive_table_view::TableViewItem;
use libntdsextract2::ntds::{EntryAttribute, NtdsAttributeId};
use crate::walk::attribute_column::AttributeColumn;
#[derive(Clone)]
pub(crate) struct AttributeLine {
name: String,
r#type: &'static str,
value: String,
}
impl AttributeLine {
pub fn from(id: &NtdsAttributeId, attr: &EntryAttribute) -> Self {
let name: &'static str = id.into();
let r#type = attr.r#type();
Self {
name: name.to_owned(),
r#type,
value: attr.original_record().format_attribute(*id).ok().flatten().unwrap_or("".to_owned())
}
}
}
impl TableViewItem<AttributeColumn> for AttributeLine {
fn to_column(&self, column: AttributeColumn) -> String {
match column {
AttributeColumn::Name => self.name.clone(),
AttributeColumn::Type => self.r#type.to_owned(),
AttributeColumn::Value => self.value.clone(),
}
}
fn cmp(&self, other: &Self, column: AttributeColumn) -> std::cmp::Ordering
where
Self: Sized,
{
match column {
AttributeColumn::Name => self.name.cmp(&other.name),
AttributeColumn::Type => self.r#type.cmp(other.r#type),
AttributeColumn::Value => self.value.cmp(&other.value),
}
}
}