Skip to content

Commit

Permalink
Change underlyng lambda trait from FnMut to Fn
Browse files Browse the repository at this point in the history
  • Loading branch information
RadicalZephyr committed Jun 19, 2020
1 parent 58de9ce commit 06fc217
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/cell.rs
Expand Up @@ -170,7 +170,7 @@ impl<A: Clone + Send + 'static> Cell<A> {
}
}

pub fn listen_weak<K: FnMut(&A) + Send + Sync + 'static>(&self, k: K) -> Listener {
pub fn listen_weak<K: Fn(&A) + Send + Sync + 'static>(&self, k: K) -> Listener {
Listener {
impl_: self.impl_.listen_weak(k),
}
Expand Down
12 changes: 6 additions & 6 deletions src/impl_/cell.rs
Expand Up @@ -235,7 +235,7 @@ impl<A: Send + 'static> Cell<A> {

pub fn map<B: Send + 'static, FN: IsLambda1<A, B> + Send + Sync + 'static>(
&self,
mut f: FN,
f: FN,
) -> Cell<B>
where
A: Clone,
Expand Down Expand Up @@ -314,7 +314,7 @@ impl<A: Send + 'static> Cell<A> {
&self,
cb: &Cell<B>,
cc: &Cell<C>,
mut f: FN,
f: FN,
) -> Cell<D>
where
A: Clone,
Expand All @@ -340,7 +340,7 @@ impl<A: Send + 'static> Cell<A> {
cb: &Cell<B>,
cc: &Cell<C>,
cd: &Cell<D>,
mut f: FN,
f: FN,
) -> Cell<E>
where
A: Clone,
Expand Down Expand Up @@ -371,7 +371,7 @@ impl<A: Send + 'static> Cell<A> {
cc: &Cell<C>,
cd: &Cell<D>,
ce: &Cell<E>,
mut f: FN,
f: FN,
) -> Cell<F>
where
A: Clone,
Expand Down Expand Up @@ -405,7 +405,7 @@ impl<A: Send + 'static> Cell<A> {
cd: &Cell<D>,
ce: &Cell<E>,
cf: &Cell<F>,
mut f: FN,
f: FN,
) -> Cell<G>
where
A: Clone,
Expand Down Expand Up @@ -598,7 +598,7 @@ impl<A: Send + 'static> Cell<A> {
.hold_lazy(Lazy::new(move || cca2.sample().sample()))
}

pub fn listen_weak<K: FnMut(&A) + Send + Sync + 'static>(&self, k: K) -> Listener
pub fn listen_weak<K: Fn(&A) + Send + Sync + 'static>(&self, k: K) -> Listener
where
A: Clone,
{
Expand Down
70 changes: 34 additions & 36 deletions src/impl_/lambda.rs
Expand Up @@ -42,32 +42,32 @@ pub fn lambda6_deps<A, B, C, D, E, F, G, FN: IsLambda6<A, B, C, D, E, F, G>>(f:
}

pub trait IsLambda1<A, B> {
fn call(&mut self, a: &A) -> B;
fn call(&self, a: &A) -> B;
fn deps_op(&self) -> Option<&Vec<Dep>>;
}

pub trait IsLambda2<A, B, C> {
fn call(&mut self, a: &A, b: &B) -> C;
fn call(&self, a: &A, b: &B) -> C;
fn deps_op(&self) -> Option<&Vec<Dep>>;
}

pub trait IsLambda3<A, B, C, D> {
fn call(&mut self, a: &A, b: &B, c: &C) -> D;
fn call(&self, a: &A, b: &B, c: &C) -> D;
fn deps_op(&self) -> Option<&Vec<Dep>>;
}

pub trait IsLambda4<A, B, C, D, E> {
fn call(&mut self, a: &A, b: &B, c: &C, d: &D) -> E;
fn call(&self, a: &A, b: &B, c: &C, d: &D) -> E;
fn deps_op(&self) -> Option<&Vec<Dep>>;
}

pub trait IsLambda5<A, B, C, D, E, F> {
fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E) -> F;
fn call(&self, a: &A, b: &B, c: &C, d: &D, e: &E) -> F;
fn deps_op(&self) -> Option<&Vec<Dep>>;
}

pub trait IsLambda6<A, B, C, D, E, F, G> {
fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> G;
fn call(&self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> G;
fn deps_op(&self) -> Option<&Vec<Dep>>;
}

Expand All @@ -81,8 +81,8 @@ impl<A, B, FN: FnMut(&A) -> B> IsLambda1<A, B> for Lambda<FN> {
}
}

impl<A, B, FN: FnMut(&A) -> B> IsLambda1<A, B> for FN {
fn call(&mut self, a: &A) -> B {
impl<A, B, FN: Fn(&A) -> B> IsLambda1<A, B> for FN {
fn call(&self, a: &A) -> B {
self(a)
}

Expand All @@ -91,8 +91,8 @@ impl<A, B, FN: FnMut(&A) -> B> IsLambda1<A, B> for FN {
}
}

impl<A, B, C, FN: FnMut(&A, &B) -> C> IsLambda2<A, B, C> for Lambda<FN> {
fn call(&mut self, a: &A, b: &B) -> C {
impl<A, B, C, FN: Fn(&A, &B) -> C> IsLambda2<A, B, C> for Lambda<FN> {
fn call(&self, a: &A, b: &B) -> C {
(self.f)(a, b)
}

Expand All @@ -101,8 +101,8 @@ impl<A, B, C, FN: FnMut(&A, &B) -> C> IsLambda2<A, B, C> for Lambda<FN> {
}
}

impl<A, B, C, FN: FnMut(&A, &B) -> C> IsLambda2<A, B, C> for FN {
fn call(&mut self, a: &A, b: &B) -> C {
impl<A, B, C, FN: Fn(&A, &B) -> C> IsLambda2<A, B, C> for FN {
fn call(&self, a: &A, b: &B) -> C {
self(a, b)
}

Expand All @@ -111,8 +111,8 @@ impl<A, B, C, FN: FnMut(&A, &B) -> C> IsLambda2<A, B, C> for FN {
}
}

impl<A, B, C, D, FN: FnMut(&A, &B, &C) -> D> IsLambda3<A, B, C, D> for Lambda<FN> {
fn call(&mut self, a: &A, b: &B, c: &C) -> D {
impl<A, B, C, D, FN: Fn(&A, &B, &C) -> D> IsLambda3<A, B, C, D> for Lambda<FN> {
fn call(&self, a: &A, b: &B, c: &C) -> D {
(self.f)(a, b, c)
}

Expand All @@ -121,8 +121,8 @@ impl<A, B, C, D, FN: FnMut(&A, &B, &C) -> D> IsLambda3<A, B, C, D> for Lambda<FN
}
}

impl<A, B, C, D, FN: FnMut(&A, &B, &C) -> D> IsLambda3<A, B, C, D> for FN {
fn call(&mut self, a: &A, b: &B, c: &C) -> D {
impl<A, B, C, D, FN: Fn(&A, &B, &C) -> D> IsLambda3<A, B, C, D> for FN {
fn call(&self, a: &A, b: &B, c: &C) -> D {
self(a, b, c)
}

Expand All @@ -131,8 +131,8 @@ impl<A, B, C, D, FN: FnMut(&A, &B, &C) -> D> IsLambda3<A, B, C, D> for FN {
}
}

impl<A, B, C, D, E, FN: FnMut(&A, &B, &C, &D) -> E> IsLambda4<A, B, C, D, E> for Lambda<FN> {
fn call(&mut self, a: &A, b: &B, c: &C, d: &D) -> E {
impl<A, B, C, D, E, FN: Fn(&A, &B, &C, &D) -> E> IsLambda4<A, B, C, D, E> for Lambda<FN> {
fn call(&self, a: &A, b: &B, c: &C, d: &D) -> E {
(self.f)(a, b, c, d)
}

Expand All @@ -141,8 +141,8 @@ impl<A, B, C, D, E, FN: FnMut(&A, &B, &C, &D) -> E> IsLambda4<A, B, C, D, E> for
}
}

impl<A, B, C, D, E, FN: FnMut(&A, &B, &C, &D) -> E> IsLambda4<A, B, C, D, E> for FN {
fn call(&mut self, a: &A, b: &B, c: &C, d: &D) -> E {
impl<A, B, C, D, E, FN: Fn(&A, &B, &C, &D) -> E> IsLambda4<A, B, C, D, E> for FN {
fn call(&self, a: &A, b: &B, c: &C, d: &D) -> E {
self(a, b, c, d)
}

Expand All @@ -151,10 +151,8 @@ impl<A, B, C, D, E, FN: FnMut(&A, &B, &C, &D) -> E> IsLambda4<A, B, C, D, E> for
}
}

impl<A, B, C, D, E, F, FN: FnMut(&A, &B, &C, &D, &E) -> F> IsLambda5<A, B, C, D, E, F>
for Lambda<FN>
{
fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E) -> F {
impl<A, B, C, D, E, F, FN: Fn(&A, &B, &C, &D, &E) -> F> IsLambda5<A, B, C, D, E, F> for Lambda<FN> {
fn call(&self, a: &A, b: &B, c: &C, d: &D, e: &E) -> F {
(self.f)(a, b, c, d, e)
}

Expand All @@ -163,8 +161,8 @@ impl<A, B, C, D, E, F, FN: FnMut(&A, &B, &C, &D, &E) -> F> IsLambda5<A, B, C, D,
}
}

impl<A, B, C, D, E, F, FN: FnMut(&A, &B, &C, &D, &E) -> F> IsLambda5<A, B, C, D, E, F> for FN {
fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E) -> F {
impl<A, B, C, D, E, F, FN: Fn(&A, &B, &C, &D, &E) -> F> IsLambda5<A, B, C, D, E, F> for FN {
fn call(&self, a: &A, b: &B, c: &C, d: &D, e: &E) -> F {
self(a, b, c, d, e)
}

Expand All @@ -173,10 +171,10 @@ impl<A, B, C, D, E, F, FN: FnMut(&A, &B, &C, &D, &E) -> F> IsLambda5<A, B, C, D,
}
}

impl<A, B, C, D, E, F, G, FN: FnMut(&A, &B, &C, &D, &E, &F) -> G> IsLambda6<A, B, C, D, E, F, G>
impl<A, B, C, D, E, F, G, FN: Fn(&A, &B, &C, &D, &E, &F) -> G> IsLambda6<A, B, C, D, E, F, G>
for Lambda<FN>
{
fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> G {
fn call(&self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> G {
(self.f)(a, b, c, d, e, f)
}

Expand All @@ -185,10 +183,10 @@ impl<A, B, C, D, E, F, G, FN: FnMut(&A, &B, &C, &D, &E, &F) -> G> IsLambda6<A, B
}
}

impl<A, B, C, D, E, F, G, FN: FnMut(&A, &B, &C, &D, &E, &F) -> G> IsLambda6<A, B, C, D, E, F, G>
impl<A, B, C, D, E, F, G, FN: Fn(&A, &B, &C, &D, &E, &F) -> G> IsLambda6<A, B, C, D, E, F, G>
for FN
{
fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> G {
fn call(&self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> G {
self(a, b, c, d, e, f)
}

Expand All @@ -197,30 +195,30 @@ impl<A, B, C, D, E, F, G, FN: FnMut(&A, &B, &C, &D, &E, &F) -> G> IsLambda6<A, B
}
}

pub fn lambda1<A, B, FN: FnMut(&A) -> B>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
pub fn lambda1<A, B, FN: Fn(&A) -> B>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
Lambda { f, deps }
}

pub fn lambda2<A, B, C, FN: FnMut(&A, &B) -> C>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
pub fn lambda2<A, B, C, FN: Fn(&A, &B) -> C>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
Lambda { f, deps }
}

pub fn lambda3<A, B, C, D, FN: FnMut(&A, &B, &C) -> D>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
pub fn lambda3<A, B, C, D, FN: Fn(&A, &B, &C) -> D>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
Lambda { f, deps }
}

pub fn lambda4<A, B, C, D, E, FN: FnMut(&A, &B, &C, &D) -> E>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
pub fn lambda4<A, B, C, D, E, FN: Fn(&A, &B, &C, &D) -> E>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
Lambda { f, deps }
}

pub fn lambda5<A, B, C, D, E, F, FN: FnMut(&A, &B, &C, &D, &E) -> F>(
pub fn lambda5<A, B, C, D, E, F, FN: Fn(&A, &B, &C, &D, &E) -> F>(
f: FN,
deps: Vec<Dep>,
) -> Lambda<FN> {
Lambda { f, deps }
}

pub fn lambda6<A, B, C, D, E, F, G, FN: FnMut(&A, &B, &C, &D, &E, &F) -> G>(
pub fn lambda6<A, B, C, D, E, F, G, FN: Fn(&A, &B, &C, &D, &E, &F) -> G>(
f: FN,
deps: Vec<Dep>,
) -> Lambda<FN> {
Expand Down
13 changes: 5 additions & 8 deletions src/impl_/stream.rs
Expand Up @@ -205,7 +205,7 @@ impl<A: Send + 'static> Stream<A> {
>(
&self,
cb: &Cell<B>,
mut f: FN,
f: FN,
) -> Stream<C> {
let cb = cb.clone();
let mut f_deps = lambda2_deps(&f);
Expand All @@ -219,7 +219,7 @@ impl<A: Send + 'static> Stream<A> {

pub fn map<B: Send + 'static, FN: IsLambda1<A, B> + Send + Sync + 'static>(
&self,
mut f: FN,
f: FN,
) -> Stream<B> {
let self_ = self.clone();
let sodium_ctx = self.sodium_ctx().clone();
Expand All @@ -243,10 +243,7 @@ impl<A: Send + 'static> Stream<A> {
})
}

pub fn filter<PRED: IsLambda1<A, bool> + Send + Sync + 'static>(
&self,
mut pred: PRED,
) -> Stream<A>
pub fn filter<PRED: IsLambda1<A, bool> + Send + Sync + 'static>(&self, pred: PRED) -> Stream<A>
where
A: Clone,
{
Expand Down Expand Up @@ -283,7 +280,7 @@ impl<A: Send + 'static> Stream<A> {
pub fn merge<FN: IsLambda2<A, A, A> + Send + Sync + 'static>(
&self,
s2: &Stream<A>,
mut f: FN,
f: FN,
) -> Stream<A>
where
A: Clone,
Expand Down Expand Up @@ -434,7 +431,7 @@ impl<A: Send + 'static> Stream<A> {

pub fn _listen<K: IsLambda1<A, ()> + Send + Sync + 'static>(
&self,
mut k: K,
k: K,
weak: bool,
) -> Listener {
let self_ = self.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/stream.rs
Expand Up @@ -67,7 +67,7 @@ impl<A: Clone + Send + 'static> Stream<A> {
&self,
cb: &Cell<B>,
cc: &Cell<C>,
mut f: FN,
f: FN,
) -> Stream<D> {
let deps: Vec<Dep>;
if let Some(deps2) = f.deps_op() {
Expand Down

0 comments on commit 06fc217

Please sign in to comment.