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
use std::{io, str};

/// Variant record reference bases.
pub trait ReferenceBases {
    /// Returns whether there are any reference bases.
    fn is_empty(&self) -> bool;

    /// Returns the number of reference bases.
    fn len(&self) -> usize;

    /// Returns an iterator over reference bases.
    fn iter(&self) -> Box<dyn Iterator<Item = io::Result<u8>> + '_>;
}

impl ReferenceBases for &str {
    fn is_empty(&self) -> bool {
        str::is_empty(self)
    }

    fn len(&self) -> usize {
        str::len(self)
    }

    fn iter(&self) -> Box<dyn Iterator<Item = io::Result<u8>> + '_> {
        Box::new(self.as_bytes().iter().copied().map(Ok))
    }
}

impl ReferenceBases for Box<dyn ReferenceBases + '_> {
    fn is_empty(&self) -> bool {
        (**self).is_empty()
    }

    fn len(&self) -> usize {
        (**self).len()
    }

    fn iter(&self) -> Box<dyn Iterator<Item = io::Result<u8>> + '_> {
        (**self).iter()
    }
}