-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It doesn't match the upcoming changes to VectorSubscriber.
- Loading branch information
Showing
2 changed files
with
0 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,3 @@ | |
//! The primary entry point of this library is [`VectorExt`]. | ||
|
||
pub mod vector; | ||
|
||
pub use vector::VectorExt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,5 @@ | ||
//! Utilities around [`ObservableVector`]. | ||
|
||
use eyeball_im::{ObservableVector, Vector, VectorSubscriber}; | ||
|
||
mod filter; | ||
|
||
pub use self::filter::{Filter, FilterMap}; | ||
|
||
/// Extension trait for [`ObservableVector`]. | ||
pub trait VectorExt<T> | ||
where | ||
T: Clone + Send + Sync + 'static, | ||
{ | ||
/// Obtain a new subscriber that filters items by the given filter function. | ||
/// | ||
/// Returns a filtered version of the current vector, and a subscriber to | ||
/// get updates through. | ||
fn subscribe_filter<F>(&self, f: F) -> (Vector<T>, Filter<VectorSubscriber<T>, F>) | ||
where | ||
F: Fn(&T) -> bool; | ||
|
||
/// Obtain a new subscriber that filters and maps items with the given | ||
/// function. | ||
/// | ||
/// Returns a filtered + mapped version of the current vector, and a | ||
/// subscriber to get updates through. | ||
fn subscribe_filter_map<U, F>(&self, f: F) -> (Vector<U>, FilterMap<VectorSubscriber<T>, F>) | ||
where | ||
U: Clone, | ||
F: Fn(T) -> Option<U>; | ||
} | ||
|
||
impl<T> VectorExt<T> for ObservableVector<T> | ||
where | ||
T: Clone + Send + Sync + 'static, | ||
{ | ||
fn subscribe_filter<F>(&self, f: F) -> (Vector<T>, Filter<VectorSubscriber<T>, F>) | ||
where | ||
F: Fn(&T) -> bool, | ||
{ | ||
Filter::new((*self).clone(), self.subscribe(), f) | ||
} | ||
|
||
fn subscribe_filter_map<U, F>(&self, f: F) -> (Vector<U>, FilterMap<VectorSubscriber<T>, F>) | ||
where | ||
U: Clone, | ||
F: Fn(T) -> Option<U>, | ||
{ | ||
FilterMap::new((*self).clone(), self.subscribe(), f) | ||
} | ||
} |