Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. use std::str::Chars;
  2.  
  3. fn main() {
  4. let foo = Foo::new();
  5. }
  6.  
  7. struct Foo<'a> {
  8. chars: Chars<'a>
  9. }
  10. impl<'a> Foo<'a> {
  11. pub fn new() -> Self {
  12. let s = "value".to_string();
  13. Foo { chars: s.chars() }
  14. }
  15. }
  16.  
  17. error: `s` does not live long enough
  18. --> <anon>:13:22
  19. 13 |> Foo { chars: s.chars() }
  20. |> ^
  21. note: reference must be valid for the lifetime 'a as defined on the block at 11:25...
  22. --> <anon>:11:26
  23. 11 |> pub fn new() -> Self {
  24. |> ^
  25. note: ...but borrowed value is only valid for the block suffix following statement 0 at 12:36
  26. --> <anon>:12:37
  27. 12 |> let s = "value".to_string();
  28. |>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement