Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. // This compiles without error on stable and beta but gives a borrow
  2. // error on nightly. It worked as of nightly 6e5a32547.
  3.  
  4. // Replacing the .by_ref() with explicitly taking a &mut ref fixes it.
  5. // Other more dubious things fix it also.
  6.  
  7. pub type Session = i32;
  8.  
  9. pub struct StreamParser<'a, T: Iterator<Item=i32>> {
  10. _tokens: T,
  11. _session: &'a mut Session,
  12. }
  13.  
  14. impl<'a, T: Iterator<Item=i32>> StreamParser<'a, T> {
  15. pub fn thing(&mut self) -> bool { true }
  16. }
  17.  
  18.  
  19. pub fn parse_stream<T: Iterator<Item=i32>, U, F>(
  20. session: &mut Session,
  21. tokens: T,
  22. f: F) -> U
  23. where F: Fn(&mut StreamParser<T>) -> U {
  24.  
  25. let mut tokp = StreamParser { _tokens: tokens, _session: session };
  26. f(&mut tokp)
  27. }
  28.  
  29. pub fn thing(session: &mut Session) {
  30. let toks = vec!(1, 2, 3);
  31. let mut stream = toks.into_iter();
  32.  
  33. let _b = parse_stream(session,
  34. stream.by_ref(),
  35. // If the by_ref is replaced with &mut stream
  36. // it works on nightly
  37. //&mut stream,
  38. |p| p.thing());
  39.  
  40. }
  41.  
  42. fn main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement