Skip to content

make FileStat hashable, and Paths serializable #12822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/libserialize/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Core encoding and decoding interfaces.
*/

use std::path;
use std::rc::Rc;
use std::vec;
use std::vec_ng::Vec;
Expand Down Expand Up @@ -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
//
Expand Down
4 changes: 3 additions & 1 deletion src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/path/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/libstd/path/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/deriving/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down