Guest User

Untitled

a guest
Mar 23rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. use std::borrow::Cow;
  2.  
  3. fn remove_spaces<'a, T: 'a + AsRef<str>>(input: & 'a T) -> Cow<'a, str> {
  4. if input.as_ref().contains(' ') {
  5. let mut buf = String::with_capacity(input.as_ref().len());
  6. for c in input.as_ref().chars() {
  7. if c!= ' ' {
  8. buf.push(c);
  9. }
  10. }
  11. return Cow::Owned(buf);
  12. }
  13. return Cow::Borrowed(input.as_ref());
  14. }
  15.  
  16. fn main() {
  17. let x = "he llo,wor ld!".to_string();
  18. let ret = remove_spaces(&x);
  19. println!("{:?}", ret);
  20. }
Add Comment
Please, Sign In to add comment