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
use access::DataIndex;
pub trait FieldSelect {
fn field<Label>(&self) -> <Self as SelectFieldByLabel<Label>>::Output
where
Self: SelectFieldByLabel<Label>,
{
SelectFieldByLabel::select_field(self)
}
}
pub trait SelectFieldByLabel<Label> {
type DType;
type Output: DataIndex<DType = Self::DType>;
fn select_field(&self) -> Self::Output;
}
#[cfg(test)]
mod tests {
use super::FieldSelect;
use access::DataIndex;
use field::Value;
#[cfg(feature = "test-utils")]
use test_utils::*;
#[cfg(feature = "test-utils")]
#[test]
fn select() {
use test_utils::emp_table::*;
let dv = sample_merged_emp_table();
println!("{}", dv);
let result = dv
.field::<EmpId>()
.iter()
.map(|datum: Value<&u64>| if datum.exists() { 1i64 } else { 0 })
.collect::<Vec<_>>();
assert_eq!(result, vec![1, 1, 1, 1, 1, 1, 1]);
}
}