Implement masking in FileType hashing on Unix

Commit 77005950f09d2f9ba54962bf5adc3f2bc3a7213f implemented masking of
FileType to fix an issue[^1] in the semantic of FileType comparison.
This commit introduces masking to Hash to maintain the invariant that
x == y => hash(x) == hash(y).

[^1]: https://github.com/rust-lang/rust/issues/104900
This commit is contained in:
Arthur Carcano 2022-12-06 10:35:34 +01:00
parent 6259028862
commit 4198d2975d

View File

@ -332,7 +332,7 @@ pub struct FileTimes {
modified: Option<SystemTime>,
}
#[derive(Copy, Clone, Eq, Hash, Debug)]
#[derive(Copy, Clone, Eq, Debug)]
pub struct FileType {
mode: mode_t,
}
@ -342,6 +342,13 @@ impl PartialEq for FileType {
self.masked() == other.masked()
}
}
impl core::hash::Hash for FileType {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.masked().hash(state);
}
}
#[derive(Debug)]
pub struct DirBuilder {
mode: mode_t,