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