diff options
| author | bors <bors@rust-lang.org> | 2014-05-12 21:45:13 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-12 21:45:13 -0700 |
| commit | 967366e988a811ae0fb47d3ad5ce0499a1414a43 (patch) | |
| tree | c42be234281609b117790f1c0b6d9db800543e5e /src/libstd | |
| parent | 1ee5e7f18511b95ddb83e725d46de0fee43825cf (diff) | |
| parent | 5001a666650962f00137f126247c50fa1188a599 (diff) | |
| download | rust-967366e988a811ae0fb47d3ad5ce0499a1414a43.tar.gz rust-967366e988a811ae0fb47d3ad5ce0499a1414a43.zip | |
auto merge of #14164 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/fs.rs | 20 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io/process.rs | 1 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 2 | ||||
| -rw-r--r-- | src/libstd/option.rs | 27 | ||||
| -rw-r--r-- | src/libstd/os.rs | 5 | ||||
| -rw-r--r-- | src/libstd/rt/rtio.rs | 1 |
7 files changed, 34 insertions, 26 deletions
diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 125b4ddad88..a497ffd40a0 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -214,6 +214,11 @@ impl File { pub fn eof(&self) -> bool { self.last_nread == 0 } + + /// Queries information about the underlying file. + pub fn stat(&mut self) -> IoResult<FileStat> { + self.fd.fstat() + } } /// Unlink a file from the underlying filesystem. @@ -887,9 +892,12 @@ mod test { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_stat_correct_on_is_file.txt"); { - let mut fs = File::open_mode(filename, Open, ReadWrite); + let mut fs = check!(File::open_mode(filename, Open, ReadWrite)); let msg = "hw"; fs.write(msg.as_bytes()).unwrap(); + + let fstat_res = check!(fs.stat()); + assert_eq!(fstat_res.kind, io::TypeFile); } let stat_res_fn = check!(stat(filename)); assert_eq!(stat_res_fn.kind, io::TypeFile); @@ -1228,12 +1236,12 @@ mod test { check!(file.fsync()); // Do some simple things with truncation - assert_eq!(check!(stat(&path)).size, 3); + assert_eq!(check!(file.stat()).size, 3); check!(file.truncate(10)); - assert_eq!(check!(stat(&path)).size, 10); + assert_eq!(check!(file.stat()).size, 10); check!(file.write(bytes!("bar"))); check!(file.fsync()); - assert_eq!(check!(stat(&path)).size, 10); + assert_eq!(check!(file.stat()).size, 10); assert_eq!(check!(File::open(&path).read_to_end()), (Vec::from_slice(bytes!("foobar", 0, 0, 0, 0)))); @@ -1241,10 +1249,10 @@ mod test { // Ensure that the intermediate zeroes are all filled in (we're seeked // past the end of the file). check!(file.truncate(2)); - assert_eq!(check!(stat(&path)).size, 2); + assert_eq!(check!(file.stat()).size, 2); check!(file.write(bytes!("wut"))); check!(file.fsync()); - assert_eq!(check!(stat(&path)).size, 9); + assert_eq!(check!(file.stat()).size, 9); assert_eq!(check!(File::open(&path).read_to_end()), (Vec::from_slice(bytes!("fo", 0, 0, 0, 0, "wut")))); drop(file); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 37edab99915..3c32b7ca802 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -228,7 +228,6 @@ use ops::{BitOr, BitAnd, Sub}; use option::{Option, Some, None}; use os; use owned::Box; -use path::Path; use result::{Ok, Err, Result}; use slice::{Vector, MutableVector, ImmutableVector}; use str::{StrSlice, StrAllocating}; @@ -1510,14 +1509,11 @@ pub enum FileType { /// Err(e) => fail!("couldn't read foo.txt: {}", e), /// }; /// -/// println!("path: {}", info.path.display()); /// println!("byte size: {}", info.size); /// # } /// ``` #[deriving(Hash)] pub struct FileStat { - /// The path that this stat structure is describing - pub path: Path, /// The size of the file, in bytes pub size: u64, /// The kind of file this path points to (directory, file, pipe, etc.) diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 3babef6126e..529fd25dc50 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -140,6 +140,7 @@ pub struct ProcessConfig<'a> { } /// The output of a finished process. +#[deriving(Eq, TotalEq, Clone)] pub struct ProcessOutput { /// The status (exit code) of the process. pub status: ProcessExit, diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 8f0c1e41309..34ed7933c39 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -96,7 +96,7 @@ //! all the standard macros, such as `assert!`, `fail!`, `println!`, //! and `format!`, also available to all Rust code. -#![crate_id = "std#0.11-pre"] +#![crate_id = "std#0.11.0-pre"] #![comment = "The Rust standard library"] #![license = "MIT/ASL2"] #![crate_type = "rlib"] diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 8fbcd529b63..ad834f2b4d4 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -30,20 +30,23 @@ //! of a value and take action, always accounting for the `None` case. //! //! ``` -//! # // FIXME This is not the greatest first example -//! // cow_says contains the word "moo" -//! let cow_says = Some("moo"); -//! // dog_says does not contain a value -//! let dog_says: Option<&str> = None; +//! fn divide(numerator: f64, denominator: f64) -> Option<f64> { +//! if denominator == 0.0 { +//! None +//! } else { +//! Some(numerator / denominator) +//! } +//! } +//! +//! // The return value of the function is an option +//! let result = divide(2.0, 3.0); //! //! // Pattern match to retrieve the value -//! match (cow_says, dog_says) { -//! (Some(cow_words), Some(dog_words)) => { -//! println!("Cow says {} and dog says {}!", cow_words, dog_words); -//! } -//! (Some(cow_words), None) => println!("Cow says {}", cow_words), -//! (None, Some(dog_words)) => println!("Dog says {}", dog_words), -//! (None, None) => println!("Cow and dog are suspiciously silent") +//! match result { +//! // The division was valid +//! Some(x) => println!("Result: {}", x), +//! // The division was invalid +//! None => println!("Cannot divide by 0") //! } //! ``` //! diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 134cfa89a37..f7324dc08b6 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -95,13 +95,12 @@ pub fn getcwd() -> Path { #[cfg(windows)] pub mod win32 { - use iter::Iterator; use libc::types::os::arch::extra::DWORD; use libc; use option::{None, Option, Expect}; use option; use os::TMPBUF_SZ; - use slice::{MutableVector, ImmutableVector, OwnedVector}; + use slice::{MutableVector, ImmutableVector}; use str::{StrSlice, StrAllocating}; use str; use vec::Vec; @@ -142,7 +141,7 @@ pub mod win32 { } pub fn as_utf16_p<T>(s: &str, f: |*u16| -> T) -> T { - let mut t = s.to_utf16().move_iter().collect::<Vec<u16>>(); + let mut t = s.to_utf16(); // Null terminate before passing on. t.push(0u16); f(t.as_ptr()) diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index bc3a483f30d..d23d327d558 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -269,6 +269,7 @@ pub trait RtioFileStream { fn fsync(&mut self) -> IoResult<()>; fn datasync(&mut self) -> IoResult<()>; fn truncate(&mut self, offset: i64) -> IoResult<()>; + fn fstat(&mut self) -> IoResult<FileStat>; } pub trait RtioProcess { |
