Guest User

Untitled

a guest
Apr 26th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. fn hor_mirror(s: String) -> String {
  2. let bytes = s.into_bytes();
  3.  
  4. let slices: Vec<&[u8]> = bytes.split(|b| b == &b'\n').rev().collect();
  5.  
  6. let mut s = Vec::with_capacity(bytes.len());
  7.  
  8. for slice in slices {
  9. s.extend_from_slice(slice);
  10. s.push(b'\n');
  11. }
  12. s.pop();
  13. String::from_utf8(s).unwrap()
  14. }
  15.  
  16. fn vert_mirror(s: String) -> String {
  17. let mut bytes = s.into_bytes();
  18. for line in bytes.split_mut(|b| b == &b'\n') {
  19. line.reverse();
  20. }
  21. String::from_utf8(bytes).unwrap()
  22.  
  23. }
  24. // first parameter: dots have to be replaced by function of one variable
  25. fn oper<F: Fn(String) -> String>(f: F, s: String) -> String {
  26. f(s)
  27. }
Add Comment
Please, Sign In to add comment