Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This compiles without error on stable and beta but gives a borrow
- // error on nightly. It worked as of nightly 6e5a32547.
- // Replacing the .by_ref() with explicitly taking a &mut ref fixes it.
- // Other more dubious things fix it also.
- pub type Session = i32;
- pub struct StreamParser<'a, T: Iterator<Item=i32>> {
- _tokens: T,
- _session: &'a mut Session,
- }
- impl<'a, T: Iterator<Item=i32>> StreamParser<'a, T> {
- pub fn thing(&mut self) -> bool { true }
- }
- pub fn parse_stream<T: Iterator<Item=i32>, U, F>(
- session: &mut Session,
- tokens: T,
- f: F) -> U
- where F: Fn(&mut StreamParser<T>) -> U {
- let mut tokp = StreamParser { _tokens: tokens, _session: session };
- f(&mut tokp)
- }
- pub fn thing(session: &mut Session) {
- let toks = vec!(1, 2, 3);
- let mut stream = toks.into_iter();
- let _b = parse_stream(session,
- stream.by_ref(),
- // If the by_ref is replaced with &mut stream
- // it works on nightly
- //&mut stream,
- |p| p.thing());
- }
- fn main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement