I've known about the visitor pattern for a while btw. It's just that I've never thought of them as a replacement for anon iterators. The other way around is true too: once anon iters land there's less need for visitors. Only if you need the fn to be executed in the caller contxt
-
-
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
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.
-
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 ^__^.
End of conversation
New conversation -
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.