Skip to content

Commit 5da688c

Browse files
committed
revise: make Nucleotide Copy
1 parent 7e87b78 commit 5da688c

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

omics-molecule/src/compound/nucleotide.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::compound::Kind;
88

99
/// A marker trait that denotes a type of nucleotide.
1010
pub trait Nucleotide:
11-
std::fmt::Debug + std::fmt::Display + Clone + Eq + PartialEq + std::str::FromStr
11+
std::fmt::Debug + std::fmt::Display + Copy + Eq + PartialEq + std::str::FromStr
1212
{
1313
/// Gets the [`Kind`] type for a given [`Nucleotide`].
1414
fn kind(&self) -> Kind;

omics-molecule/src/compound/nucleotide/relation.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,22 @@ impl<N: Nucleotide> Relation<N> {
100100
/// use omics_molecule::polymer::dna::Nucleotide;
101101
///
102102
/// let relation = Relation::<Nucleotide>::try_new(Some(Nucleotide::A), Some(Nucleotide::C))?;
103-
/// assert_eq!(relation.reference(), Some(&Nucleotide::A));
103+
/// assert_eq!(relation.reference(), Some(Nucleotide::A));
104104
///
105105
/// let relation = Relation::<Nucleotide>::try_new(Some(Nucleotide::A), None)?;
106-
/// assert_eq!(relation.reference(), Some(&Nucleotide::A));
106+
/// assert_eq!(relation.reference(), Some(Nucleotide::A));
107107
///
108108
/// let relation = Relation::<Nucleotide>::try_new(None, Some(Nucleotide::C))?;
109109
/// assert_eq!(relation.reference(), None);
110110
///
111111
/// # Ok::<(), Box<dyn std::error::Error>>(())
112112
/// ```
113-
pub fn reference(&self) -> Option<&N> {
113+
pub fn reference(&self) -> Option<N> {
114114
match self {
115-
Relation::Identical(reference) => Some(reference),
116-
Relation::Substitution(substitution) => Some(substitution.reference()),
115+
Relation::Identical(reference) => Some(*reference),
116+
Relation::Substitution(substitution) => Some(*substitution.reference()),
117117
Relation::Insertion(_) => None,
118-
Relation::Deletion(reference) => Some(reference),
118+
Relation::Deletion(reference) => Some(*reference),
119119
}
120120
}
121121

@@ -128,21 +128,21 @@ impl<N: Nucleotide> Relation<N> {
128128
/// use omics_molecule::polymer::dna::Nucleotide;
129129
///
130130
/// let relation = Relation::<Nucleotide>::try_new(Some(Nucleotide::A), Some(Nucleotide::C))?;
131-
/// assert_eq!(relation.alternate(), Some(&Nucleotide::C));
131+
/// assert_eq!(relation.alternate(), Some(Nucleotide::C));
132132
///
133133
/// let relation = Relation::<Nucleotide>::try_new(Some(Nucleotide::A), None)?;
134134
/// assert_eq!(relation.alternate(), None);
135135
///
136136
/// let relation = Relation::<Nucleotide>::try_new(None, Some(Nucleotide::C))?;
137-
/// assert_eq!(relation.alternate(), Some(&Nucleotide::C));
137+
/// assert_eq!(relation.alternate(), Some(Nucleotide::C));
138138
///
139139
/// # Ok::<(), Box<dyn std::error::Error>>(())
140140
/// ```
141-
pub fn alternate(&self) -> Option<&N> {
141+
pub fn alternate(&self) -> Option<N> {
142142
match self {
143-
Relation::Identical(reference) => Some(reference),
144-
Relation::Substitution(substitution) => Some(substitution.alternate()),
145-
Relation::Insertion(alternate) => Some(alternate),
143+
Relation::Identical(reference) => Some(*reference),
144+
Relation::Substitution(substitution) => Some(*substitution.alternate()),
145+
Relation::Insertion(alternate) => Some(*alternate),
146146
Relation::Deletion(_) => None,
147147
}
148148
}
@@ -211,7 +211,7 @@ impl<N: Nucleotide> Relation<N> {
211211
/// ```
212212
pub fn into_nucleotides(self) -> (Option<N>, Option<N>) {
213213
match self {
214-
Relation::Identical(reference) => (Some(reference.clone()), Some(reference)),
214+
Relation::Identical(reference) => (Some(reference), Some(reference)),
215215
Relation::Substitution(substitution) => {
216216
let (reference, alternate) = substitution.into_parts();
217217
(Some(reference), Some(alternate))

omics-molecule/src/polymer/dna/nucleotide.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum Error {
4343
}
4444

4545
/// A nucleotide in an DNA context.
46-
#[derive(Clone, Debug, Eq, PartialEq)]
46+
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
4747
pub enum Nucleotide {
4848
/// Adenine.
4949
A,

omics-molecule/src/polymer/rna/nucleotide.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum Error {
4343
}
4444

4545
/// A nucleotide in an RNA context.
46-
#[derive(Clone, Debug, Eq, PartialEq)]
46+
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
4747
pub enum Nucleotide {
4848
/// Adenine.
4949
A,

omics-variation/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ mod tests {
6565
assert_eq!(snv.coordinate().contig().as_str(), "seq0");
6666
assert_eq!(snv.coordinate().strand(), Strand::Positive);
6767
assert_eq!(snv.coordinate().position().get(), 1);
68-
assert_eq!(snv.reference(), &dna::Nucleotide::A);
69-
assert_eq!(snv.alternate(), &dna::Nucleotide::C);
68+
assert_eq!(snv.reference(), dna::Nucleotide::A);
69+
assert_eq!(snv.alternate(), dna::Nucleotide::C);
7070
}
7171
}
7272

omics-variation/src/snv.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ where
149149
/// use omics_variation::snv::Variant;
150150
///
151151
/// let variant = "seq0:+:1:A:T".parse::<Variant<dna::Nucleotide>>()?;
152-
/// assert_eq!(variant.reference(), &dna::Nucleotide::A);
152+
/// assert_eq!(variant.reference(), dna::Nucleotide::A);
153153
///
154154
/// # Ok::<(), Box<dyn std::error::Error>>(())
155155
/// ```
156-
pub fn reference(&self) -> &N {
156+
pub fn reference(&self) -> N {
157157
// SAFETY: because a single nucleotide variant is guaranteed to have a
158158
// reference nucleotide within the inner [`Relation`], this will
159159
// always unwrap successfully.
@@ -171,11 +171,11 @@ where
171171
/// use omics_variation::snv::Variant;
172172
///
173173
/// let variant = "seq0:+:1:A:T".parse::<Variant<dna::Nucleotide>>()?;
174-
/// assert_eq!(variant.alternate(), &dna::Nucleotide::T);
174+
/// assert_eq!(variant.alternate(), dna::Nucleotide::T);
175175
///
176176
/// # Ok::<(), Box<dyn std::error::Error>>(())
177177
/// ```
178-
pub fn alternate(&self) -> &N {
178+
pub fn alternate(&self) -> N {
179179
// SAFETY: because a single nucleotide variant is guaranteed to have a
180180
// alternate nucleotide within the inner [`Relation`], this will
181181
// always unwrap successfully.
@@ -284,8 +284,8 @@ mod tests {
284284
assert_eq!(variant.coordinate().contig().as_str(), "seq0");
285285
assert_eq!(variant.coordinate().strand(), Strand::Positive);
286286
assert_eq!(variant.coordinate().position().get(), 1);
287-
assert_eq!(variant.reference(), &dna::Nucleotide::A);
288-
assert_eq!(variant.alternate(), &dna::Nucleotide::C);
287+
assert_eq!(variant.reference(), dna::Nucleotide::A);
288+
assert_eq!(variant.alternate(), dna::Nucleotide::C);
289289

290290
Ok(())
291291
}
@@ -297,8 +297,8 @@ mod tests {
297297
assert_eq!(variant.coordinate().contig().as_str(), "seq0");
298298
assert_eq!(variant.coordinate().strand(), Strand::Positive);
299299
assert_eq!(variant.coordinate().position().get(), 1);
300-
assert_eq!(variant.reference(), &rna::Nucleotide::U);
301-
assert_eq!(variant.alternate(), &rna::Nucleotide::C);
300+
assert_eq!(variant.reference(), rna::Nucleotide::U);
301+
assert_eq!(variant.alternate(), rna::Nucleotide::C);
302302

303303
Ok(())
304304
}
@@ -311,8 +311,8 @@ mod tests {
311311
assert_eq!(variant.coordinate().contig().as_str(), "seq0");
312312
assert_eq!(variant.coordinate().strand(), Strand::Negative);
313313
assert_eq!(variant.coordinate().position().get(), 1);
314-
assert_eq!(variant.reference(), &dna::Nucleotide::A);
315-
assert_eq!(variant.alternate(), &dna::Nucleotide::C);
314+
assert_eq!(variant.reference(), dna::Nucleotide::A);
315+
assert_eq!(variant.alternate(), dna::Nucleotide::C);
316316

317317
Ok(())
318318
}
@@ -325,8 +325,8 @@ mod tests {
325325
assert_eq!(variant.coordinate().contig().as_str(), "seq0");
326326
assert_eq!(variant.coordinate().strand(), Strand::Negative);
327327
assert_eq!(variant.coordinate().position().get(), 1);
328-
assert_eq!(variant.reference(), &rna::Nucleotide::U);
329-
assert_eq!(variant.alternate(), &rna::Nucleotide::C);
328+
assert_eq!(variant.reference(), rna::Nucleotide::U);
329+
assert_eq!(variant.alternate(), rna::Nucleotide::C);
330330

331331
Ok(())
332332
}
@@ -339,8 +339,8 @@ mod tests {
339339
assert_eq!(variant.coordinate().contig().as_str(), "seq0");
340340
assert_eq!(variant.coordinate().strand(), Strand::Positive);
341341
assert_eq!(variant.coordinate().position().get(), 1);
342-
assert_eq!(variant.reference(), &dna::Nucleotide::A);
343-
assert_eq!(variant.alternate(), &dna::Nucleotide::C);
342+
assert_eq!(variant.reference(), dna::Nucleotide::A);
343+
assert_eq!(variant.alternate(), dna::Nucleotide::C);
344344

345345
Ok(())
346346
}
@@ -353,8 +353,8 @@ mod tests {
353353
assert_eq!(variant.coordinate().contig().as_str(), "seq0");
354354
assert_eq!(variant.coordinate().strand(), Strand::Positive);
355355
assert_eq!(variant.coordinate().position().get(), 1);
356-
assert_eq!(variant.reference(), &rna::Nucleotide::U);
357-
assert_eq!(variant.alternate(), &rna::Nucleotide::C);
356+
assert_eq!(variant.reference(), rna::Nucleotide::U);
357+
assert_eq!(variant.alternate(), rna::Nucleotide::C);
358358

359359
Ok(())
360360
}

0 commit comments

Comments
 (0)