I guess the visitor pattern is a nice placeholder for anonymous iterators until we get generators. First saw this in @KodrAus's kv log code. But now also using it for my own work!
pub fn visit(&self, visitor: &mut impl FnMut(&str));
Internally call visit for each item!
-
Show this thread
-
Replying to @yoshuawuyts
In log we use something like: pub fn visit(&’a self, visitor: &mut impl FnMut(&’a str)); That little lifetime, ‘a, constrains what you can visit but lets you write methods like: pub fn get(&’a self, key: Key) -> Option<&’a Value>; based purely on the visit API.
2 replies 0 retweets 1 like
Replying to @KodrAus
Oh that's awesome, thanks for sharing! Thinking out loud here, but I wonder it lifetime elision would also work here, e.g. simplifying it further to: pub fn visit(&self, visitor: &mut impl FnMut(&'_ str)); Should try this out when I'm behind a computer again I guess ^__^.
2:24 PM - 28 Jul 2019
from Berlin, Germany
0 replies
0 retweets
1 like
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.