auto merge of #12822 : erickt/rust/cleanup, r=acrichto

This PR makes `std::io::FileStat` hashable, and `Path` serializable as a byte array.
This commit is contained in:
bors 2014-03-12 21:21:44 -07:00
commit e86e1d88b2
5 changed files with 39 additions and 10 deletions

View file

@ -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<E: Encoder> Encodable<E> for path::posix::Path {
fn encode(&self, e: &mut E) {
self.as_vec().encode(e)
}
}
impl<D: Decoder> Decodable<D> for path::posix::Path {
fn decode(d: &mut D) -> path::posix::Path {
let bytes: ~[u8] = Decodable::decode(d);
path::posix::Path::new(bytes)
}
}
impl<E: Encoder> Encodable<E> for path::windows::Path {
fn encode(&self, e: &mut E) {
self.as_vec().encode(e)
}
}
impl<D: Decoder> Decodable<D> 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
//

View file

@ -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,

View file

@ -88,10 +88,10 @@ impl ToCStr for Path {
}
}
impl<H: Writer> ::hash::Hash<H> for Path {
impl<S: Writer> ::hash::Hash<S> for Path {
#[inline]
fn hash(&self, hasher: &mut H) {
self.repr.hash(hasher)
fn hash(&self, state: &mut S) {
self.repr.hash(state)
}
}

View file

@ -112,10 +112,10 @@ impl ToCStr for Path {
}
}
impl<H: Writer> ::hash::Hash<H> for Path {
impl<S: Writer> ::hash::Hash<S> for Path {
#[inline]
fn hash(&self, hasher: &mut H) {
self.repr.hash(hasher)
fn hash(&self, state: &mut S) {
self.repr.hash(state)
}
}

View file

@ -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(),