1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::marker::PhantomData;
pub struct CloneSetFn<T: Clone, U, F: Fn(&mut T, U)>(F, PhantomData<(T, U)>);
impl<T: Clone, U, F: Fn(&mut T, U)> CloneSetFn<T, U, F> {
pub(crate) fn new(f: F) -> CloneSetFn<T, U, F> {
CloneSetFn(f, PhantomData)
}
}
impl<T: Clone, U, F: Fn(&mut T, U)> FnOnce<(&T, U)> for CloneSetFn<T, U, F> {
type Output = T;
extern "rust-call" fn call_once(self, (root, child): (&T, U)) -> T {
let mut root = root.clone();
self.0(&mut root, child);
root
}
}
impl<T: Clone, U, F: Fn(&mut T, U)> FnMut<(&T, U)> for CloneSetFn<T, U, F> {
extern "rust-call" fn call_mut(&mut self, (root, child): (&T, U)) -> T {
let mut root = root.clone();
self.0(&mut root, child);
root
}
}
impl<T: Clone, U, F: Fn(&mut T, U)> Fn<(&T, U)> for CloneSetFn<T, U, F> {
extern "rust-call" fn call(&self, (root, child): (&T, U)) -> T {
let mut root = root.clone();
self.0(&mut root, child);
root
}
}