noodles_vcf/header/record/value/map/contig.rs
1//! Inner VCF header contig map value.
2
3mod builder;
4pub(crate) mod tag;
5
6pub use self::tag::Tag;
7
8use super::{Indexed, Inner, Map};
9
10/// An inner VCF header contig map value.
11#[derive(Clone, Debug, Default, Eq, PartialEq)]
12pub struct Contig {
13 pub(crate) length: Option<usize>,
14 pub(crate) md5: Option<String>,
15 pub(crate) url: Option<String>,
16 pub(crate) idx: Option<usize>,
17}
18
19impl Inner for Contig {
20 type StandardTag = tag::Standard;
21 type Builder = builder::Builder;
22}
23
24impl Indexed for Contig {
25 fn idx(&self) -> Option<usize> {
26 self.idx
27 }
28
29 fn idx_mut(&mut self) -> &mut Option<usize> {
30 &mut self.idx
31 }
32}
33
34impl Map<Contig> {
35 /// Creates a VCF header contig map value.
36 ///
37 /// # Examples
38 ///
39 /// ```
40 /// use noodles_vcf::header::record::value::{map::Contig, Map};
41 /// let map = Map::<Contig>::new();
42 /// ```
43 pub fn new() -> Self {
44 Self::default()
45 }
46
47 /// Returns the length.
48 ///
49 /// # Examples
50 ///
51 /// ```
52 /// use noodles_vcf::header::record::value::{map::Contig, Map};
53 /// let map = Map::<Contig>::new();
54 /// assert!(map.length().is_none());
55 /// ```
56 pub fn length(&self) -> Option<usize> {
57 self.inner.length
58 }
59
60 /// Returns a mutable reference to the length.
61 ///
62 /// # Examples
63 ///
64 /// ```
65 /// use noodles_vcf::header::record::value::{map::Contig, Map};
66 ///
67 /// let mut map = Map::<Contig>::new();
68 /// assert!(map.length().is_none());
69 ///
70 /// *map.length_mut() = Some(8);
71 /// assert_eq!(map.length(), Some(8));
72 /// ```
73 pub fn length_mut(&mut self) -> &mut Option<usize> {
74 &mut self.inner.length
75 }
76
77 /// Returns the MD5 hexdigest.
78 ///
79 /// # Examples
80 ///
81 /// ```
82 /// use noodles_vcf::header::record::value::{map::Contig, Map};
83 /// let map = Map::<Contig>::new();
84 /// assert!(map.md5().is_none());
85 /// ```
86 pub fn md5(&self) -> Option<&str> {
87 self.inner.md5.as_deref()
88 }
89
90 /// Returns a mutable reference to the MD5 hexdigest.
91 ///
92 /// # Examples
93 ///
94 /// ```
95 /// use noodles_vcf::header::record::value::{map::Contig, Map};
96 ///
97 /// let mut map = Map::<Contig>::new();
98 /// assert!(map.md5().is_none());
99 ///
100 /// *map.md5_mut() = Some(String::from("d7eba311421bbc9d3ada44709dd61534"));
101 /// assert_eq!(map.md5(), Some("d7eba311421bbc9d3ada44709dd61534"));
102 /// ```
103 pub fn md5_mut(&mut self) -> &mut Option<String> {
104 &mut self.inner.md5
105 }
106
107 /// Returns the URL.
108 ///
109 /// # Examples
110 ///
111 /// ```
112 /// use noodles_vcf::header::record::value::{map::Contig, Map};
113 /// let map = Map::<Contig>::new();
114 /// assert!(map.url().is_none());
115 /// ```
116 pub fn url(&self) -> Option<&str> {
117 self.inner.url.as_deref()
118 }
119
120 /// Returns a mutable reference to the URL.
121 ///
122 /// # Examples
123 ///
124 /// ```
125 /// use noodles_vcf::header::record::value::{map::Contig, Map};
126 ///
127 /// let mut map = Map::<Contig>::new();
128 /// assert!(map.url().is_none());
129 ///
130 /// *map.url_mut() = Some(String::from("https://example.com/reference.fa"));
131 /// assert_eq!(map.url(), Some("https://example.com/reference.fa"));
132 /// ```
133 pub fn url_mut(&mut self) -> &mut Option<String> {
134 &mut self.inner.url
135 }
136}