Skip to content

Commit

Permalink
Ext: MutableVecExt::feed and feed_cloned added
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-kolarik committed Jan 11, 2025
1 parent 40c6d48 commit b2044c3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The
format is based on [Keep a Changelog], and this project aims to follow
[Semantic Versioning].

## [0.5.1] - 2025-01-11

### Added

- `feed` and `feed_cloned` added to `MutableVecExt`

## [0.4.0] - 2024-05-07

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "futures-signals-ext"
version = "0.5.0"
version = "0.5.1"
authors = ["martin.kolarik@smartcontrol.cz"]
description = "Extension to futures-signals: MutableOption with combinators, spawning, predicate driven selections from SignalVec."
edition = "2024"
Expand Down
30 changes: 29 additions & 1 deletion src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
task::{Context, Poll},
};

use crate::MutableVecEntry;
use crate::{MutableVecEntry, SignalVecSpawn};

pub trait MutableExt<A> {
fn inspect(&self, f: impl FnOnce(&A));
Expand Down Expand Up @@ -203,6 +203,14 @@ pub trait MutableVecExt<A> {
F: FnMut(&A) -> K,
K: Eq + Hash;

fn feed(&self, source: impl SignalVec<Item = A> + 'static)
where
A: Copy + 'static;

fn feed_cloned(&self, source: impl SignalVec<Item = A> + 'static)
where
A: Clone + 'static;

fn signal_vec_filter<P>(&self, p: P) -> Filter<MutableSignalVec<A>, P>
where
A: Copy,
Expand Down Expand Up @@ -508,6 +516,26 @@ impl<A> MutableVecExt<A> for MutableVec<A> {
extended
}

fn feed(&self, source: impl SignalVec<Item = A> + 'static)
where
A: Copy + 'static,
{
let this = self.clone();
source.spawn_local(move |diff| {
MutableVecLockMut::apply_vec_diff(&mut this.lock_mut(), diff);
});
}

fn feed_cloned(&self, source: impl SignalVec<Item = A> + 'static)
where
A: Clone + 'static,
{
let this = self.clone();
source.spawn_local(move |diff| {
MutableVecLockMut::apply_vec_diff(&mut this.lock_mut(), diff);
});
}

fn signal_vec_filter<P>(&self, p: P) -> Filter<MutableSignalVec<A>, P>
where
A: Copy,
Expand Down

0 comments on commit b2044c3

Please sign in to comment.