Accept FnOnce/FnMut where possible.

This commit is contained in:
Andreas Fackler 2019-09-17 17:51:41 +02:00 committed by Andreas Fackler
parent 4e525432c8
commit 9d6b851466
3 changed files with 18 additions and 14 deletions

View File

@ -30,7 +30,7 @@ where
pub fn map<F2, FF>(self, f_fault: FF) -> Fault<N, F2>
where
F2: Fail,
FF: Fn(F) -> F2,
FF: FnOnce(F) -> F2,
{
Fault {
node_id: self.node_id,
@ -94,12 +94,12 @@ where
}
/// Applies `f_fault` to each element in log, modifying its `kind` only
pub fn map<F2, FF>(self, f_fault: FF) -> FaultLog<N, F2>
pub fn map<F2, FF>(self, mut f_fault: FF) -> FaultLog<N, F2>
where
F2: Fail,
FF: Fn(F) -> F2,
FF: FnMut(F) -> F2,
{
FaultLog(self.into_iter().map(|f| f.map(&f_fault)).collect())
FaultLog(self.into_iter().map(|f| f.map(&mut f_fault)).collect())
}
}

View File

@ -61,7 +61,7 @@ pub struct TargetedMessage<M, N> {
impl<M, N> TargetedMessage<M, N> {
/// Applies the given transformation of messages, preserving the target.
pub fn map<T, F: Fn(M) -> T>(self, f: F) -> TargetedMessage<T, N> {
pub fn map<T, F: FnOnce(M) -> T>(self, f: F) -> TargetedMessage<T, N> {
TargetedMessage {
target: self.target,
message: f(self.message),

View File

@ -102,18 +102,22 @@ where
self,
f_out: FO,
f_fail: FF,
f_msg: FM,
mut f_msg: FM,
) -> Step<M2, O2, N, F2>
where
F2: Fail,
FO: Fn(O) -> O2,
FF: Fn(F) -> F2,
FM: Fn(M) -> M2,
FO: FnMut(O) -> O2,
FF: FnMut(F) -> F2,
FM: FnMut(M) -> M2,
{
Step {
output: self.output.into_iter().map(f_out).collect(),
fault_log: self.fault_log.map(f_fail),
messages: self.messages.into_iter().map(|tm| tm.map(&f_msg)).collect(),
messages: self
.messages
.into_iter()
.map(|tm| tm.map(&mut f_msg))
.collect(),
}
}
@ -123,16 +127,16 @@ where
&mut self,
other: Step<M2, O2, N, F2>,
f_fail: FF,
f_msg: FM,
mut f_msg: FM,
) -> Vec<O2>
where
F2: Fail,
FF: Fn(F2) -> F,
FM: Fn(M2) -> M,
FF: FnMut(F2) -> F,
FM: FnMut(M2) -> M,
{
let fails = other.fault_log.map(f_fail);
self.fault_log.extend(fails);
let msgs = other.messages.into_iter().map(|tm| tm.map(&f_msg));
let msgs = other.messages.into_iter().map(|tm| tm.map(&mut f_msg));
self.messages.extend(msgs);
other.output
}