Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. use std::borrow::Cow;
  2.  
  3. fn foo<'a, T: Into<Cow<'a, str>>>(arg: T) {
  4. let owned: String = match arg.into() {
  5. Cow::Borrowed(string) => string.to_owned(),
  6. Cow::Owned(string) => string,
  7. };
  8.  
  9. println!("{}", owned);
  10. }
  11.  
  12.  
  13. fn main() {
  14. let borrowed: &str = "test1";
  15. foo(borrowed);
  16. let owned: String = "test2".into();
  17. foo(owned);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement