The protein translation exercise has 2 scenarios where it can “fail”:
- When an unknown codon is encountered
- When a “codon” of partial length is encountered
Both these scenarios unfortunately have the same error string in canonical-data.
Currently this is represented with an Option
:
pub fn translate(rna: &str) -> Option<Vec<&str>>
It would make more sense, I think, if it returned a Result
with an enum Error
with an InvalidCodon
member. Many other exercises also follow this pattern, and this is a medium exercise so the student should know about Result<>
by now.
Let me know what you think, or if an Option
was picked for a reason I’m not seeing. It might not be worth breaking past solutions.
Link to the exercise for convenience: Protein Translation in Rust on Exercism