noodles_vcf/variant/record/samples/
sample.rs

1use std::io;
2
3use super::series::Value;
4use crate::Header;
5
6/// Variant record samples sample.
7pub trait Sample {
8    /// Returns the value with the given key.
9    fn get<'a, 'h: 'a>(
10        &'a self,
11        header: &'h Header,
12        key: &str,
13    ) -> Option<io::Result<Option<Value<'a>>>>;
14
15    /// Returns the value at the given index.
16    fn get_index<'a, 'h: 'a>(
17        &'a self,
18        header: &'h Header,
19        i: usize,
20    ) -> Option<io::Result<Option<Value<'a>>>>;
21
22    /// Returns an iterator over fields.
23    fn iter<'a, 'h: 'a>(
24        &'a self,
25        header: &'h Header,
26    ) -> Box<dyn Iterator<Item = io::Result<(&'a str, Option<Value<'a>>)>> + 'a>;
27}
28
29impl Sample for Box<dyn Sample + '_> {
30    fn get<'a, 'h: 'a>(
31        &'a self,
32        header: &'h Header,
33        key: &str,
34    ) -> Option<io::Result<Option<Value<'a>>>> {
35        (**self).get(header, key)
36    }
37
38    fn get_index<'a, 'h: 'a>(
39        &'a self,
40        header: &'h Header,
41        i: usize,
42    ) -> Option<io::Result<Option<Value<'a>>>> {
43        (**self).get_index(header, i)
44    }
45
46    fn iter<'a, 'h: 'a>(
47        &'a self,
48        header: &'h Header,
49    ) -> Box<dyn Iterator<Item = io::Result<(&'a str, Option<Value<'a>>)>> + 'a> {
50        (**self).iter(header)
51    }
52}