BurntSushi / walkdir

Rust library for walking directories recursively.
The Unlicense
1.22k stars 107 forks source link

Implement Clone for WalkDir #78

Closed laumann closed 6 years ago

laumann commented 6 years ago

Fixes #54

I tried out @BurntSushi's suggestion to use Arc and it seems to work.

laumann commented 6 years ago

np :-) My only worry is the unwrap()- could that cause any problems, do you think?

BurntSushi commented 6 years ago

@laumann Oh! Thanks so much for pointing that out, I completely missed that. Yeah, we definitely can't do that. Which means you can't borrow the function mutably, which in turn means you can't call it. So we have three choices:

  1. Turn FnMut into Fn.
  2. Use Arc<Mutex<FnMut(...)>> instead of Arc<FnMut(...)>.
  3. Don't make WalkDir cloneable.

I'm inclined to go with option (3) for a variety of reasons that have kind of already been hashed out. That is, we want calls to be able to do mutation inside the closure, and adding the overhead of a mutex to the sorting function isn't acceptable I think. So I think this PR can be closed. :-(

laumann commented 6 years ago

That's OK. It seemed so simple... :-)