From be12c9f753fa742dd76127a600ba9f2447d19b39 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 10 Mar 2014 20:47:25 -0700 Subject: [PATCH 1/3] std: allow io::File* structs to be hashable --- src/libstd/io/mod.rs | 4 +++- src/libstd/path/posix.rs | 6 +++--- src/libstd/path/windows.rs | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 1c10c7b61c3..c6795fad1a5 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1320,7 +1320,7 @@ pub enum FileAccess { } /// Different kinds of files which can be identified by a call to stat -#[deriving(Eq, Show)] +#[deriving(Eq, Show, Hash)] pub enum FileType { /// This is a normal file, corresponding to `S_IFREG` TypeFile, @@ -1358,6 +1358,7 @@ pub enum FileType { /// println!("byte size: {}", info.size); /// # } /// ``` +#[deriving(Hash)] pub struct FileStat { /// The path that this stat structure is describing path: Path, @@ -1399,6 +1400,7 @@ pub struct FileStat { /// have different meanings or no meaning at all on some platforms. #[unstable] #[allow(missing_doc)] +#[deriving(Hash)] pub struct UnstableFileStat { device: u64, inode: u64, diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index f7588f6ca59..8345a2d04d1 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -88,10 +88,10 @@ impl ToCStr for Path { } } -impl ::hash::Hash for Path { +impl ::hash::Hash for Path { #[inline] - fn hash(&self, hasher: &mut H) { - self.repr.hash(hasher) + fn hash(&self, state: &mut S) { + self.repr.hash(state) } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 6d05001beab..180078ae959 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -112,10 +112,10 @@ impl ToCStr for Path { } } -impl ::hash::Hash for Path { +impl ::hash::Hash for Path { #[inline] - fn hash(&self, hasher: &mut H) { - self.repr.hash(hasher) + fn hash(&self, state: &mut S) { + self.repr.hash(state) } } From d2cfd543f764c4a3bab9149fe54233c4aa20e6d5 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 10 Mar 2014 20:47:47 -0700 Subject: [PATCH 2/3] serialize: make Paths serializable --- src/libserialize/serialize.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs index a94df9975a4..115bb6cb6f3 100644 --- a/src/libserialize/serialize.rs +++ b/src/libserialize/serialize.rs @@ -14,6 +14,7 @@ Core encoding and decoding interfaces. */ +use std::path; use std::rc::Rc; use std::vec; use std::vec_ng::Vec; @@ -625,6 +626,32 @@ impl< } } +impl Encodable for path::posix::Path { + fn encode(&self, e: &mut E) { + self.as_vec().encode(e) + } +} + +impl Decodable for path::posix::Path { + fn decode(d: &mut D) -> path::posix::Path { + let bytes: ~[u8] = Decodable::decode(d); + path::posix::Path::new(bytes) + } +} + +impl Encodable for path::windows::Path { + fn encode(&self, e: &mut E) { + self.as_vec().encode(e) + } +} + +impl Decodable for path::windows::Path { + fn decode(d: &mut D) -> path::windows::Path { + let bytes: ~[u8] = Decodable::decode(d); + path::windows::Path::new(bytes) + } +} + // ___________________________________________________________________________ // Helper routines // From 62026fd6b64296c85a8150119e2cd6a162b8b5e0 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 11 Mar 2014 20:07:42 -0700 Subject: [PATCH 3/3] syntax: change the #[deriving(Hash)] typaram variable name --- src/libsyntax/ext/deriving/hash.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/ext/deriving/hash.rs b/src/libsyntax/ext/deriving/hash.rs index 299989d5fe6..a94feee9d37 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax/ext/deriving/hash.rs @@ -24,12 +24,12 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt, let (path, generics, args) = if cx.ecfg.deriving_hash_type_parameter { (Path::new_(vec!("std", "hash", "Hash"), None, - vec!(~Literal(Path::new_local("__H"))), true), + vec!(~Literal(Path::new_local("__S"))), true), LifetimeBounds { lifetimes: Vec::new(), - bounds: vec!(("__H", vec!(Path::new(vec!("std", "io", "Writer"))))), + bounds: vec!(("__S", vec!(Path::new(vec!("std", "io", "Writer"))))), }, - Path::new_local("__H")) + Path::new_local("__S")) } else { (Path::new(vec!("std", "hash", "Hash")), LifetimeBounds::empty(),