/// A set of directories, files and modules that rustfmt should ignore.
#[derive(Default, Deserialize, Serialize, Clone, Debug)]
-pub struct IgnoreList {
- directories: Option<HashSet<PathBuf>>,
- files: Option<HashSet<PathBuf>>,
-}
+pub struct IgnoreList(HashSet<PathBuf>);
impl IgnoreList {
- fn add_prefix_inner(set: &HashSet<PathBuf>, dir: &Path) -> HashSet<PathBuf> {
- set.iter()
+ pub fn add_prefix(&mut self, dir: &Path) {
+ self.0 = self.0
+ .iter()
.map(|s| {
if s.has_root() {
s.clone()
path
}
})
- .collect()
- }
-
- pub fn add_prefix(&mut self, dir: &Path) {
- macro add_prefix_inner_with ($($field: ident),* $(,)*) {
- $(if let Some(set) = self.$field.as_mut() {
- *set = IgnoreList::add_prefix_inner(set, dir);
- })*
- }
-
- add_prefix_inner_with!(directories, files);
+ .collect();
}
- fn is_ignore_file(&self, path: &Path) -> bool {
- self.files.as_ref().map_or(false, |set| set.contains(path))
- }
-
- fn is_under_ignore_dir(&self, path: &Path) -> bool {
- if let Some(ref dirs) = self.directories {
- for dir in dirs {
- if path.starts_with(dir) {
- return true;
- }
+ fn skip_file_inner(&self, file: &Path) -> bool {
+ for path in &self.0 {
+ if file.starts_with(path) {
+ return true;
}
}
pub fn skip_file(&self, file: &FileName) -> bool {
if let FileName::Real(ref path) = file {
- self.is_ignore_file(path) || self.is_under_ignore_dir(path)
+ self.skip_file_inner(path)
} else {
false
}