Make WalkDir Send + Sync

Fixes #41
This commit is contained in:
Jérémie Lawson 2017-08-04 08:19:09 +10:00 committed by Andrew Gallant
parent 079d1456eb
commit 107750f24e
2 changed files with 17 additions and 3 deletions

View File

@ -126,7 +126,6 @@ use std::fmt;
use std::fs::{self, FileType, ReadDir}; use std::fs::{self, FileType, ReadDir};
use std::io; use std::io;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::ffi::OsString;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::result; use std::result;
use std::vec; use std::vec;
@ -252,7 +251,7 @@ struct WalkDirOptions {
max_open: usize, max_open: usize,
min_depth: usize, min_depth: usize,
max_depth: usize, max_depth: usize,
sorter: Option<Box<FnMut(&DirEntry,&DirEntry) -> Ordering + 'static>>, sorter: Option<Box<FnMut(&DirEntry,&DirEntry) -> Ordering + Send + Sync + 'static>>,
contents_first: bool, contents_first: bool,
} }
@ -382,7 +381,7 @@ impl WalkDir {
/// WalkDir::new("foo").sort_by(|a,b| a.file_name().cmp(b.file_name())); /// WalkDir::new("foo").sort_by(|a,b| a.file_name().cmp(b.file_name()));
/// ``` /// ```
pub fn sort_by<F>(mut self, cmp: F) -> Self pub fn sort_by<F>(mut self, cmp: F) -> Self
where F: FnMut(&DirEntry, &DirEntry) -> Ordering + 'static { where F: FnMut(&DirEntry, &DirEntry) -> Ordering + Send + Sync + 'static {
self.opts.sorter = Some(Box::new(cmp)); self.opts.sorter = Some(Box::new(cmp));
self self
} }

View File

@ -792,3 +792,18 @@ fn walk_dir_sort_small_fd_max() {
assert_eq!(got, assert_eq!(got,
["", "/foo", "/foo/abc", "/foo/abc/fit", "/foo/bar", "/foo/faz"]); ["", "/foo", "/foo/abc", "/foo/abc/fit", "/foo/bar", "/foo/faz"]);
} }
#[test]
fn walk_dir_send_sync_traits() {
use FilterEntry;
fn assert_send<T: Send>() {}
fn assert_sync<T: Sync>() {}
assert_send::<WalkDir>();
assert_sync::<WalkDir>();
assert_send::<IntoIter>();
assert_sync::<IntoIter>();
assert_send::<FilterEntry<IntoIter, u8>>();
assert_sync::<FilterEntry<IntoIter, u8>>();
}