Separate Labelled from LabelsLoader

This commit is contained in:
edouardparis 2024-12-17 16:39:14 +01:00
parent 0d8f88839e
commit b1abce5a24
3 changed files with 12 additions and 2 deletions

View File

@ -5,7 +5,7 @@ use std::{collections::HashMap, iter::IntoIterator, sync::Arc};
use crate::{
app::{error::Error, message::Message, view},
daemon::{
model::{LabelItem, Labelled},
model::{LabelItem, Labelled, LabelsLoader},
Daemon,
},
};

View File

@ -333,7 +333,7 @@ pub trait Daemon: Debug {
}
}
async fn load_labels<T: model::Labelled, D: Daemon + ?Sized>(
async fn load_labels<T: model::Labelled + model::LabelsLoader, D: Daemon + ?Sized>(
daemon: &D,
targets: &mut Vec<T>,
) -> Result<(), DaemonError> {

View File

@ -447,6 +447,16 @@ impl Labelled for HistoryTransaction {
pub trait Labelled {
fn labelled(&self) -> Vec<LabelItem>;
fn labels(&mut self) -> &mut HashMap<String, String>;
}
pub trait LabelsLoader {
fn load_labels(&mut self, new_labels: &HashMap<String, Option<String>>);
}
impl<T: ?Sized> LabelsLoader for T
where
T: Labelled,
{
fn load_labels(&mut self, new_labels: &HashMap<String, Option<String>>) {
let items = self.labelled();
let labels = self.labels();