Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn hor_mirror(s: String) -> String {
- let bytes = s.into_bytes();
- let slices: Vec<&[u8]> = bytes.split(|b| b == &b'\n').rev().collect();
- let mut s = Vec::with_capacity(bytes.len());
- for slice in slices {
- s.extend_from_slice(slice);
- s.push(b'\n');
- }
- s.pop();
- String::from_utf8(s).unwrap()
- }
- fn vert_mirror(s: String) -> String {
- let mut bytes = s.into_bytes();
- for line in bytes.split_mut(|b| b == &b'\n') {
- line.reverse();
- }
- String::from_utf8(bytes).unwrap()
- }
- // first parameter: dots have to be replaced by function of one variable
- fn oper<F: Fn(String) -> String>(f: F, s: String) -> String {
- f(s)
- }
Add Comment
Please, Sign In to add comment