noodles_sam/header/record/value/map/reference_sequence.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 76 77 78 79 80 81 82 83 84 85 86
//! SAM header record reference sequence map value.
mod builder;
pub mod md5_checksum;
pub mod molecule_topology;
pub mod tag;
use std::num::NonZeroUsize;
pub use self::md5_checksum::Md5Checksum;
pub(crate) use self::tag::Tag;
use self::builder::Builder;
use super::{Inner, Map, OtherFields};
/// A SAM header record reference sequence map value.
///
/// The reference sequence describes a sequence a read possibly mapped to. The length is guaranteed
/// to be set.
///
/// A list of reference sequences creates a reference sequence dictionary.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ReferenceSequence {
pub(crate) length: NonZeroUsize,
}
impl Inner for ReferenceSequence {
type StandardTag = tag::Standard;
type Builder = Builder;
}
impl Map<ReferenceSequence> {
/// Creates a reference sequence with a length.
///
/// # Examples
///
/// ```
/// use std::num::NonZeroUsize;
/// use noodles_sam::header::record::value::{map::ReferenceSequence, Map};
/// let reference_sequence = Map::<ReferenceSequence>::new(NonZeroUsize::try_from(13)?);
/// # Ok::<_, std::num::TryFromIntError>(())
/// ```
pub fn new(length: NonZeroUsize) -> Self {
Self {
inner: ReferenceSequence { length },
other_fields: OtherFields::new(),
}
}
/// Returns the reference sequence length.
///
/// # Examples
///
/// ```
/// use std::num::NonZeroUsize;
/// use noodles_sam::header::record::value::{map::ReferenceSequence, Map};
/// let reference_sequence = Map::<ReferenceSequence>::new(NonZeroUsize::try_from(13)?);
/// assert_eq!(usize::from(reference_sequence.length()), 13);
/// # Ok::<_, std::num::TryFromIntError>(())
/// ```
pub fn length(&self) -> NonZeroUsize {
self.inner.length
}
/// Returns a mutable reference to the reference sequence length.
///
/// # Examples
///
/// ```
/// use std::num::NonZeroUsize;
///
/// use noodles_sam::header::record::value::{map::ReferenceSequence, Map};
///
/// let length = NonZeroUsize::try_from(13)?;
/// let mut reference_sequence = Map::<ReferenceSequence>::new(length);
/// assert_eq!(reference_sequence.length(), length);
///
/// let length = NonZeroUsize::try_from(8)?;
/// *reference_sequence.length_mut() = length;
/// assert_eq!(reference_sequence.length(), length);
/// # Ok::<_, std::num::TryFromIntError>(())
/// ```
pub fn length_mut(&mut self) -> &mut NonZeroUsize {
&mut self.inner.length
}
}