Skip to content

Commit

Permalink
Implement AsRef for DnaSequence (#52)
Browse files Browse the repository at this point in the history
* Implement AsRef for DnaSequence

* Test AsRef impl
  • Loading branch information
lynn authored Jan 31, 2024
1 parent 7303a94 commit 07dd15f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/rust_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ impl<T: NucleotideLike> FromStr for DnaSequence<T> {
}
}

impl<T: NucleotideLike> AsRef<[T]> for DnaSequence<T> {
fn as_ref(&self) -> &[T] {
self.as_slice()
}
}

impl DnaSequence<Nucleotide> {
/// Return canonical isomorphic DNA sequence.
///
Expand Down Expand Up @@ -778,6 +784,13 @@ mod tests {
protein(" an gtnattag \t");
}

#[test]
fn test_as_ref() {
let sequence = dna("ac");
let nucleotides: &[NucleotideAmbiguous] = sequence.as_ref();
assert!(nucleotides == &[NucleotideAmbiguous::A, NucleotideAmbiguous::C]);
}

#[cfg(feature = "serde")]
#[test]
fn test_serde_json() {
Expand Down

0 comments on commit 07dd15f

Please sign in to comment.