逆序倒转

  1. pub fn reverse(text: &str) -> String {
  2. text.chars().rev().collect()
  3. }
  4. #[cfg(test)]
  5. mod tests {
  6. use super::*;
  7. #[test]
  8. fn test_simple() {
  9. assert_eq!(reverse("racecar"), "racecar");
  10. }
  11. #[test]
  12. fn test_sentence() {
  13. assert_eq!(reverse("step on no pets"), "step on no pets");
  14. }
  15. }