Skip to content

Commit

Permalink
sam/lazy/record/sequence: Implement crate::alignment::record::Sequenc…
Browse files Browse the repository at this point in the history
…e for Sequence
  • Loading branch information
zaeleus committed Dec 13, 2023
1 parent 1d6068e commit 61b6f65
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions noodles-sam/src/lazy/record/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Iterator<Item = u8> + '_> {
Box::new(self.as_ref().iter().copied())
}
}

impl<'a> TryInto<crate::record::Sequence> for Sequence<'a> {
type Error = io::Error;

Expand All @@ -42,3 +56,21 @@ impl<'a> TryInto<crate::record::Sequence> 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']);
}
}

0 comments on commit 61b6f65

Please sign in to comment.