diff --git a/noodles-sam/src/lazy/record/sequence.rs b/noodles-sam/src/lazy/record/sequence.rs index 507ec0e8a..3c13f3b4a 100644 --- a/noodles-sam/src/lazy/record/sequence.rs +++ b/noodles-sam/src/lazy/record/sequence.rs @@ -26,6 +26,20 @@ impl<'a> AsRef<[u8]> for Sequence<'a> { } } +impl<'a> crate::alignment::record::Sequence for Sequence<'a> { + fn is_empty(&self) -> bool { + self.is_empty() + } + + fn len(&self) -> usize { + self.len() + } + + fn iter(&self) -> Box + '_> { + Box::new(self.as_ref().iter().copied()) + } +} + impl<'a> TryInto for Sequence<'a> { type Error = io::Error; @@ -42,3 +56,21 @@ impl<'a> TryInto for Sequence<'a> { Ok(sequence) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_crate_alignment_record_sequence_iter() { + fn t(src: &[u8]) { + let sequence: &dyn crate::alignment::record::Sequence = &Sequence::new(src); + let actual: Vec<_> = sequence.iter().collect(); + assert_eq!(actual, src); + } + + t(&[]); + t(&[b'A', b'C', b'G']); + t(&[b'A', b'C', b'G', b'T']); + } +}