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