noodles_sam/alignment/record_buf/
quality_scores.rs1use std::{
2 io,
3 ops::{Index, IndexMut},
4};
5
6use noodles_core::position::SequenceIndex;
7
8#[derive(Clone, Debug, Default, Eq, PartialEq)]
10pub struct QualityScores(Vec<u8>);
11
12impl QualityScores {
13 pub fn is_empty(&self) -> bool {
15 self.0.is_empty()
16 }
17}
18
19impl AsRef<[u8]> for QualityScores {
20 fn as_ref(&self) -> &[u8] {
21 &self.0
22 }
23}
24
25impl AsMut<Vec<u8>> for QualityScores {
26 fn as_mut(&mut self) -> &mut Vec<u8> {
27 &mut self.0
28 }
29}
30
31impl From<Vec<u8>> for QualityScores {
32 fn from(values: Vec<u8>) -> Self {
33 Self(values)
34 }
35}
36
37impl<I> Index<I> for QualityScores
38where
39 I: SequenceIndex<u8>,
40{
41 type Output = I::Output;
42
43 fn index(&self, index: I) -> &Self::Output {
44 index.index(&self.0)
45 }
46}
47
48impl<I> IndexMut<I> for QualityScores
49where
50 I: SequenceIndex<u8>,
51{
52 fn index_mut(&mut self, index: I) -> &mut Self::Output {
53 index.index_mut(&mut self.0)
54 }
55}
56
57impl From<QualityScores> for Vec<u8> {
58 fn from(quality_scores: QualityScores) -> Self {
59 quality_scores.0
60 }
61}
62
63impl crate::alignment::record::QualityScores for &QualityScores {
64 fn is_empty(&self) -> bool {
65 self.0.is_empty()
66 }
67
68 fn len(&self) -> usize {
69 self.0.len()
70 }
71
72 fn iter(&self) -> Box<dyn Iterator<Item = io::Result<u8>> + '_> {
73 Box::new(self.0.iter().copied().map(Ok))
74 }
75}