org_social_lib_rs/feed_view.rs
1//! Feed view trait and implementations for different feed display and filtering strategies.
2//!
3//! This module defines the `FeedView` trait that allows different views to be created
4//! over a shared collection of posts and profiles. Views can filter, sort, and present
5//! the data in different ways while sharing the underlying data.
6
7use crate::{feed, post::Post};
8
9/// A trait for different views over feed data.
10///
11/// Feed views provide different ways to present and interact with the same
12/// underlying collection of posts and profiles. Views share references to
13/// the posts without cloning the actual post data.
14pub trait FeedView {
15 /// Update the view with new posts and profiles.
16 /// This is called by the parent Feed when the underlying data changes, and when the view is first added.
17 fn update_content(&mut self, feed: &feed::Feed);
18
19 /// Get the number of posts in this view.
20 fn len(&self) -> usize;
21
22 /// Check if this view is empty.
23 fn is_empty(&self) -> bool {
24 self.len() == 0
25 }
26
27 /// Get a display name for this view.
28 fn view_name(&self) -> &str;
29
30 /// Refresh the view - recompute any derived data
31 fn refresh(&mut self);
32
33 /// Apply a filter function to the posts in this view
34 fn apply_filter(&mut self, filter_fn: Box<dyn Fn(&Post) -> bool>);
35}