Guest User

Untitled

a guest
Jul 20th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. trait Foo {
  2. fn get<'a> (self: &'a Self) -> Option<&'a str>;
  3. fn insert (self: &mut Self, _: String);
  4. }
  5.  
  6. fn bar (foo: &mut Foo)
  7. {
  8. if let Some(s_ref) = foo.get() {
  9. return println!("{}", s_ref)
  10. }
  11. foo.insert(42.to_string())
  12. }
  13.  
  14. fn bad (foo: &mut Foo)
  15. {
  16. if let Some(s_ref) = foo.get() {
  17. println!("{}", s_ref)
  18. } else {
  19. foo.insert(42.to_string())
  20. }
  21. }
  22.  
  23. fn bad_unsugared (foo: &mut Foo)
  24. {
  25. match foo.get() {
  26. Some(s_ref) => println!("{}", s_ref),
  27. _ => foo.insert(42.to_string()),
  28. }
  29. }
  30.  
  31. fn baz (foo: &mut Foo) -> &str
  32. {
  33. if let Some(s_ref) = foo.get() {
  34. return s_ref
  35. }
  36. foo.insert(42.to_string());
  37. unimplemented!()
  38. }
  39.  
  40. fn main () {}
Add Comment
Please, Sign In to add comment