nikis05 / derive-visitor

MIT License
20 stars 6 forks source link

Visit with closure #2

Closed badicsalex closed 2 years ago

badicsalex commented 2 years ago

Hi,

I'm planning on using your crate for one of my projects, and I thought it would be great to have a default method on the Drive trait which accepts a closure instead of a full Visitor struct to reduce boilerplate.

Something along the lines of

let sum = 0;
my_complex_struct.visit_all(|node: &InnerStruct| { sum += node.value });

I'm pretty sure I'll implement this functionality in some kind of util.rs in the project, but it would be better to 'upstream' this functionality IMO. If you think too, I'd be happy to create a PR.

nikis05 commented 2 years ago

I think I could blanket implement Visitor for FnMut<T>(item: T, event: Event) and for FnMut<T>(item: T) (Event::Enter only). Would it suffice your use case?

badicsalex commented 2 years ago

Implementing visitor for Fn didn't even occur to me, but it would look great, yeah.