mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
add has_phrase
This commit is contained in:
parent
f783984a74
commit
32eb1bf085
2 changed files with 9 additions and 6 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue