Apply exported sorting to items itself and nested items

This commit is contained in:
2023-08-07 14:16:44 +02:00
parent 376bfb2852
commit e84a39b7c4
6 changed files with 242 additions and 1 deletions

View File

@@ -70,6 +70,16 @@ impl Sortable for DataCatalogue {
fn sorting_key(&self) -> String {
self.name.clone()
}
fn sorted(&mut self) -> &Self {
self.entries
.entry
.sort_unstable_by_key(|item| item.sorting_key());
self.entries.entry.iter_mut().for_each(|item| {
item.sorted();
});
self
}
}
impl Comparable for DataCatalogue {
@@ -151,6 +161,23 @@ pub struct Entry {
revision: u16,
}
impl Sortable for Entry {
fn sorting_key(&self) -> String {
self.name.clone()
}
fn sorted(&mut self) -> &Self
where
Self: Sized,
{
if let Some(ref mut use_) = self.use_ {
use_.program_module
.sort_unstable_by_key(|item| item.sorting_key())
}
self
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Use {
@@ -166,3 +193,9 @@ pub struct ProgramModule {
#[serde(rename = "@name")]
name: String,
}
impl Sortable for ProgramModule {
fn sorting_key(&self) -> String {
format!("{}-{}", self.program, self.name)
}
}