Skip to content

Commit

Permalink
sam/lazy/record/cigar: Implement crate::alignment::record::Cigar for …
Browse files Browse the repository at this point in the history
…Cigar
  • Loading branch information
zaeleus committed Dec 14, 2023
1 parent f251100 commit d7150f6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions noodles-sam/src/lazy/record/cigar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,36 @@ impl<'a> Cigar<'a> {
}
}

impl<'a> crate::alignment::record::Cigar for Cigar<'a> {
fn is_empty(&self) -> bool {
self.is_empty()
}

fn len(&self) -> usize {
self.as_ref()
.iter()
.filter(|&b| {
matches!(
b,
b'M' | b'I' | b'D' | b'N' | b'S' | b'H' | b'P' | b'=' | b'X'
)
})
.count()
}

fn iter(&self) -> Box<dyn Iterator<Item = io::Result<(u8, usize)>> + '_> {
Box::new(self.iter().map(|result| {
result
.map(|op| {
// SAFETY: `char::from(op)` only returns ASCII characters.
let raw_op = char::from(op.kind()) as u8;
(raw_op, op.len())
})
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
}))
}
}

impl<'a> AsRef<[u8]> for Cigar<'a> {
fn as_ref(&self) -> &[u8] {
self.0
Expand Down

0 comments on commit d7150f6

Please sign in to comment.