From 49eec236ef01aa2489b72ad23a03cd8a90911768 Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 31 Jan 2024 16:37:45 +0100 Subject: [PATCH 1/2] Implement AsRef for DnaSequence --- src/rust_api.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rust_api.rs b/src/rust_api.rs index f52f217..3de1555 100644 --- a/src/rust_api.rs +++ b/src/rust_api.rs @@ -337,6 +337,12 @@ impl FromStr for DnaSequence { } } +impl AsRef<[T]> for DnaSequence { + fn as_ref(&self) -> &[T] { + self.as_slice() + } +} + impl DnaSequence { /// Return canonical isomorphic DNA sequence. /// From 7ffbbbdc678015e8b4321b00ef033d0a9363d88e Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 31 Jan 2024 16:43:12 +0100 Subject: [PATCH 2/2] Test AsRef impl --- src/rust_api.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/rust_api.rs b/src/rust_api.rs index 3de1555..6a69cca 100644 --- a/src/rust_api.rs +++ b/src/rust_api.rs @@ -784,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() {