add has_phrase

This commit is contained in:
🪞👃🪞 2024-12-14 23:24:07 +01:00
parent f783984a74
commit 32eb1bf085
2 changed files with 9 additions and 6 deletions

View file

@ -18,6 +18,14 @@ pub trait HasPhrase {
fn phrase (&self) -> &Arc<RwLock<Phrase>>;
}
#[macro_export] macro_rules! has_phrase {
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
impl $(<$($L),*$($T $(: $U)?),*>)? HasPhrase for $Struct $(<$($L),*$($T),*>)? {
fn phrase (&$self) -> &Arc<RwLock<Phrase>> { &$cb }
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum PhrasePoolCommand {
Add(usize, Phrase),

View file

@ -181,12 +181,7 @@ impl From<&Arc<RwLock<Phrase>>> for PhraseListModel {
}
has_phrases!(|self:PhraseListModel|self.phrases);
impl HasPhrase for PhraseListModel {
fn phrase (&self) -> &Arc<RwLock<Phrase>> {
&self.phrases[self.phrase_index()]
}
}
has_phrase!(|self:PhraseListModel|self.phrases[self.phrase_index()]);
impl PhraseListModel {
pub(crate) fn phrase_index (&self) -> usize {