Skip to content

Commit e86e1d8

Browse files
committed
auto merge of #12822 : erickt/rust/cleanup, r=acrichto
This PR makes `std::io::FileStat` hashable, and `Path` serializable as a byte array.
2 parents a53242a + 62026fd commit e86e1d8

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

src/libserialize/serialize.rs

+27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Core encoding and decoding interfaces.
1515
*/
1616

17+
use std::path;
1718
use std::rc::Rc;
1819
use std::vec;
1920
use std::vec_ng::Vec;
@@ -625,6 +626,32 @@ impl<
625626
}
626627
}
627628

629+
impl<E: Encoder> Encodable<E> for path::posix::Path {
630+
fn encode(&self, e: &mut E) {
631+
self.as_vec().encode(e)
632+
}
633+
}
634+
635+
impl<D: Decoder> Decodable<D> for path::posix::Path {
636+
fn decode(d: &mut D) -> path::posix::Path {
637+
let bytes: ~[u8] = Decodable::decode(d);
638+
path::posix::Path::new(bytes)
639+
}
640+
}
641+
642+
impl<E: Encoder> Encodable<E> for path::windows::Path {
643+
fn encode(&self, e: &mut E) {
644+
self.as_vec().encode(e)
645+
}
646+
}
647+
648+
impl<D: Decoder> Decodable<D> for path::windows::Path {
649+
fn decode(d: &mut D) -> path::windows::Path {
650+
let bytes: ~[u8] = Decodable::decode(d);
651+
path::windows::Path::new(bytes)
652+
}
653+
}
654+
628655
// ___________________________________________________________________________
629656
// Helper routines
630657
//

src/libstd/io/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ pub enum FileAccess {
13201320
}
13211321

13221322
/// Different kinds of files which can be identified by a call to stat
1323-
#[deriving(Eq, Show)]
1323+
#[deriving(Eq, Show, Hash)]
13241324
pub enum FileType {
13251325
/// This is a normal file, corresponding to `S_IFREG`
13261326
TypeFile,
@@ -1358,6 +1358,7 @@ pub enum FileType {
13581358
/// println!("byte size: {}", info.size);
13591359
/// # }
13601360
/// ```
1361+
#[deriving(Hash)]
13611362
pub struct FileStat {
13621363
/// The path that this stat structure is describing
13631364
path: Path,
@@ -1399,6 +1400,7 @@ pub struct FileStat {
13991400
/// have different meanings or no meaning at all on some platforms.
14001401
#[unstable]
14011402
#[allow(missing_doc)]
1403+
#[deriving(Hash)]
14021404
pub struct UnstableFileStat {
14031405
device: u64,
14041406
inode: u64,

src/libstd/path/posix.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ impl ToCStr for Path {
8888
}
8989
}
9090

91-
impl<H: Writer> ::hash::Hash<H> for Path {
91+
impl<S: Writer> ::hash::Hash<S> for Path {
9292
#[inline]
93-
fn hash(&self, hasher: &mut H) {
94-
self.repr.hash(hasher)
93+
fn hash(&self, state: &mut S) {
94+
self.repr.hash(state)
9595
}
9696
}
9797

src/libstd/path/windows.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ impl ToCStr for Path {
112112
}
113113
}
114114

115-
impl<H: Writer> ::hash::Hash<H> for Path {
115+
impl<S: Writer> ::hash::Hash<S> for Path {
116116
#[inline]
117-
fn hash(&self, hasher: &mut H) {
118-
self.repr.hash(hasher)
117+
fn hash(&self, state: &mut S) {
118+
self.repr.hash(state)
119119
}
120120
}
121121

src/libsyntax/ext/deriving/hash.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
2424

2525
let (path, generics, args) = if cx.ecfg.deriving_hash_type_parameter {
2626
(Path::new_(vec!("std", "hash", "Hash"), None,
27-
vec!(~Literal(Path::new_local("__H"))), true),
27+
vec!(~Literal(Path::new_local("__S"))), true),
2828
LifetimeBounds {
2929
lifetimes: Vec::new(),
30-
bounds: vec!(("__H", vec!(Path::new(vec!("std", "io", "Writer"))))),
30+
bounds: vec!(("__S", vec!(Path::new(vec!("std", "io", "Writer"))))),
3131
},
32-
Path::new_local("__H"))
32+
Path::new_local("__S"))
3333
} else {
3434
(Path::new(vec!("std", "hash", "Hash")),
3535
LifetimeBounds::empty(),

0 commit comments

Comments
 (0)