noodles_sam/alignment/record/cigar/
op.rs

1//! Alignment record CIGAR operation.
2
3pub mod kind;
4
5pub use self::kind::Kind;
6
7/// An alignment record CIGAR operation.
8#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub struct Op {
10    kind: Kind,
11    len: usize,
12}
13
14impl Op {
15    /// Creates a CIGAR operation.
16    ///
17    /// # Examples
18    ///
19    /// ```
20    /// use noodles_sam::alignment::record::cigar::{op::Kind, Op};
21    ///
22    /// let op = Op::new(Kind::Match, 13);
23    ///
24    /// assert_eq!(op.kind(), Kind::Match);
25    /// assert_eq!(op.len(), 13);
26    /// ```
27    pub const fn new(kind: Kind, len: usize) -> Self {
28        Self { kind, len }
29    }
30
31    /// Returns the kind of the operation.
32    ///
33    /// # Examples
34    ///
35    /// ```
36    /// use noodles_sam::alignment::record::cigar::{op::Kind, Op};
37    /// let op = Op::new(Kind::Match, 13);
38    /// assert_eq!(op.kind(), Kind::Match);
39    /// ```
40    pub fn kind(self) -> Kind {
41        self.kind
42    }
43
44    /// Returns the length of the operation.
45    ///
46    /// # Examples
47    ///
48    /// ```
49    /// use noodles_sam::alignment::record::cigar::{op::Kind, Op};
50    /// let op = Op::new(Kind::Match, 13);
51    /// assert_eq!(op.len(), 13);
52    /// ```
53    pub fn len(self) -> usize {
54        self.len
55    }
56
57    /// Returns whether the operation is a no-op.
58    ///
59    /// That is, whether the operation has a length of 0.
60    ///
61    /// # Examples
62    ///
63    /// ```
64    /// use noodles_sam::alignment::record::cigar::{op::Kind, Op};
65    ///
66    /// let op = Op::new(Kind::Match, 0);
67    /// assert!(op.is_empty());
68    ///
69    /// let op = Op::new(Kind::Match, 13);
70    /// assert!(!op.is_empty());
71    /// ```
72    pub fn is_empty(self) -> bool {
73        self.len == 0
74    }
75}