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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use super::*;
pub trait RetainMut<T>
{
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` for which `f(&e)` returns `false`.
/// This method operates in place, visiting each element exactly once in the
/// original order, and preserves the order of the retained elements.
fn retain_mut<F>(&mut self, f: F)
where
F: FnMut(&mut T) -> bool;
}
impl<T> RetainMut<T> for Vec<T>
{
fn retain_mut<F>(&mut self, f: F)
where
F: FnMut(&mut T) -> bool,
{
self.retain_mut(f);
}
}
impl<T> RetainMut<T> for VecDeque<T>
{
fn retain_mut<F>(&mut self, f: F)
where
F: FnMut(&mut T) -> bool,
{
self.retain_mut(f);
}
}
/*
Retain for Vec: Fn(&T)
Retain for String: Fn(char) (can make a wrapper to use Fn(&char))
Retain for HashMap: Fn(&K, &mut V) (idk how to wrap it properly)
???
pub trait Retain
{
type Item<'a> : where Self: 'a;
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` for which `f(&e)` returns `false`.
/// This method operates in place, visiting each element exactly once in the
/// original order, and preserves the order of the retained elements.
fn retain<F>(&mut self, f: F)
where
F: FnMut(Self::Item<'a>) -> bool;
}
*/
/*
pub trait Retain<T>
{
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` for which `f(&e)` returns `false`.
/// This method operates in place, visiting each element exactly once in the
/// original order, and preserves the order of the retained elements.
fn retain<F>(&mut self, f: F)
where
F: FnMut(&T) -> bool;
}
impl<T> Retain<T> for Vec<T>
{
fn retain<F>(&mut self, f: F)
where
F: FnMut(&T) -> bool {
self.retain(f);
}
}
impl<T> Retain<T> for VecDeque<T>
{
fn retain<F>(&mut self, f: F)
where
F: FnMut(&T) -> bool {
self.retain(f);
}
}
impl Retain<char> for String
{
fn retain<F>(&mut self, mut f: F)
where
F: FnMut(&char) -> bool {
self.retain(|c| f(&c));
}
}
/*
impl<K,V> Retain<(K,V)> for HashMap<K,V>
{
fn retain<F>(&mut self, f: F)
where
F: FnMut(&(K,V)) -> bool {
self.retain(|k,v| f(&(k,v)));
}
}
#[cfg(feature = "std")]
impl<T> RetainMut<T> for VecDeque<T>
{
fn retain_mut<F>(&mut self, f: F)
where
F: FnMut(&mut T) -> bool {
self.retain_mut(f);
}
}
*/
*/