Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Foo {
- fn get<'a> (self: &'a Self) -> Option<&'a str>;
- fn insert (self: &mut Self, _: String);
- }
- fn bar (foo: &mut Foo)
- {
- if let Some(s_ref) = foo.get() {
- return println!("{}", s_ref)
- }
- foo.insert(42.to_string())
- }
- fn bad (foo: &mut Foo)
- {
- if let Some(s_ref) = foo.get() {
- println!("{}", s_ref)
- } else {
- foo.insert(42.to_string())
- }
- }
- fn bad_unsugared (foo: &mut Foo)
- {
- match foo.get() {
- Some(s_ref) => println!("{}", s_ref),
- _ => foo.insert(42.to_string()),
- }
- }
- fn baz (foo: &mut Foo) -> &str
- {
- if let Some(s_ref) = foo.get() {
- return s_ref
- }
- foo.insert(42.to_string());
- unimplemented!()
- }
- fn main () {}
Add Comment
Please, Sign In to add comment