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
use super::Rescore;
use crate::util::ShouldSkip;
#[derive(Default, Clone, PartialEq, Serialize)]
pub struct RescoreCollection(Vec<Rescore>);
impl std::fmt::Debug for RescoreCollection {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl IntoIterator for RescoreCollection {
type Item = Rescore;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl ShouldSkip for RescoreCollection {
fn should_skip(&self) -> bool {
self.0.should_skip()
}
}
impl RescoreCollection {
pub fn new() -> Self {
Default::default()
}
pub fn extend<T>(&mut self, rescore: T)
where
T: IntoIterator,
T::Item: Into<Rescore>,
{
self.0.extend(
rescore
.into_iter()
.map(Into::into)
.filter(ShouldSkip::should_keep),
)
}
}