mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-24 03:24:21 +01:00
add TimelineCache helper methods
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -38,6 +38,15 @@ impl<'a, M> Vitality<'a, M> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> IntoIterator for &'a mut TimelineCache {
|
||||||
|
type Item = (&'a TimelineKind, &'a mut Timeline);
|
||||||
|
type IntoIter = std::collections::hash_map::IterMut<'a, TimelineKind, Timeline>;
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
self.timelines.iter_mut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TimelineCache {
|
impl TimelineCache {
|
||||||
/// Pop a timeline from the timeline cache. This only removes the timeline
|
/// Pop a timeline from the timeline cache. This only removes the timeline
|
||||||
/// if it has reached 0 subscribers, meaning it was the last one to be
|
/// if it has reached 0 subscribers, meaning it was the last one to be
|
||||||
@@ -95,6 +104,14 @@ impl TimelineCache {
|
|||||||
self.timelines.insert(id, timeline);
|
self.timelines.insert(id, timeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn insert(&mut self, id: TimelineKind, timeline: Timeline) {
|
||||||
|
if let Some(_cur_timeline) = self.timelines.get_mut(&id) {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
self.timelines.insert(id, timeline);
|
||||||
|
}
|
||||||
|
|
||||||
/// Get and/or update the notes associated with this timeline
|
/// Get and/or update the notes associated with this timeline
|
||||||
pub fn notes<'a>(
|
pub fn notes<'a>(
|
||||||
&'a mut self,
|
&'a mut self,
|
||||||
@@ -190,6 +207,18 @@ impl TimelineCache {
|
|||||||
|
|
||||||
open_result
|
open_result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get(&self, id: &TimelineKind) -> Option<&Timeline> {
|
||||||
|
self.timelines.get(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_mut(&mut self, id: &TimelineKind) -> Option<&mut Timeline> {
|
||||||
|
self.timelines.get_mut(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn num_timelines(&self) -> usize {
|
||||||
|
self.timelines.len()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Look for new thread notes since our last fetch
|
/// Look for new thread notes since our last fetch
|
||||||
|
|||||||
Reference in New Issue
Block a user