Skip to content

Commit

Permalink
im-util: Remove VectorExt
Browse files Browse the repository at this point in the history
It doesn't match the upcoming changes to VectorSubscriber.
  • Loading branch information
jplatte committed Sep 6, 2023
1 parent 85a2e30 commit 647e860
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 48 deletions.
2 changes: 0 additions & 2 deletions eyeball-im-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
//! The primary entry point of this library is [`VectorExt`].

pub mod vector;

pub use vector::VectorExt;
46 changes: 0 additions & 46 deletions eyeball-im-util/src/vector.rs
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)
}
}

0 comments on commit 647e860

Please sign in to comment.