@@ -45,17 +45,17 @@ use path::Path;
45
45
use super :: super :: test:: * ;
46
46
47
47
/// Open a file for reading/writing, as indicated by `path`.
48
- ///
48
+ ///
49
49
/// # Example
50
- ///
50
+ ///
51
51
/// use std;
52
52
/// use std::path::Path;
53
53
/// use std::rt::io::support::PathLike;
54
54
/// use std::rt::io::file::open;
55
55
/// use std::rt::io::{FileMode, FileAccess};
56
- ///
56
+ ///
57
57
/// let p = &Path("/some/file/path.txt");
58
- ///
58
+ ///
59
59
/// do io_error::cond.trap(|_| {
60
60
/// // hoo-boy...
61
61
/// }).inside {
@@ -64,26 +64,26 @@ use super::super::test::*;
64
64
/// None => fail!("whoops! I'm sure this raised, anyways..");
65
65
/// }
66
66
/// // do some stuff with that stream
67
- ///
67
+ ///
68
68
/// // the file stream will be closed at the end of this block
69
69
/// }
70
70
/// // ..
71
- ///
71
+ ///
72
72
/// `FileMode` and `FileAccess` provide information about the permissions
73
73
/// context in which a given stream is created. More information about them
74
74
/// can be found in `std::rt::io`'s docs.
75
- ///
75
+ ///
76
76
/// Note that, with this function, a `FileStream` is returned regardless of
77
77
/// the access-limitations indicated by `FileAccess` (e.g. calling `write` on a
78
78
/// `FileStream` opened as `ReadOnly` will raise an `io_error` condition at runtime). If you
79
79
/// desire a more-correctly-constrained interface to files, use the
80
80
/// `{open_stream, open_reader, open_writer}` methods that are a part of `FileInfo`
81
- ///
81
+ ///
82
82
/// # Errors
83
- ///
83
+ ///
84
84
/// This function will raise an `io_error` condition under a number of different circumstances,
85
85
/// to include but not limited to:
86
- ///
86
+ ///
87
87
/// * Opening a file that already exists with `FileMode` of `Create` or vice versa (e.g.
88
88
/// opening a non-existant file with `FileMode` or `Open`)
89
89
/// * Attempting to open a file with a `FileAccess` that the user lacks permissions
@@ -110,25 +110,25 @@ pub fn open<P: PathLike>(path: &P,
110
110
}
111
111
112
112
/// Unlink a file from the underlying filesystem.
113
- ///
113
+ ///
114
114
/// # Example
115
- ///
115
+ ///
116
116
/// use std;
117
117
/// use std::path::Path;
118
118
/// use std::rt::io::support::PathLike;
119
119
/// use std::rt::io::file::unlink;
120
- ///
120
+ ///
121
121
/// let p = &Path("/some/file/path.txt");
122
122
/// unlink(p);
123
123
/// // if we made it here without failing, then the
124
124
/// // unlink operation was successful
125
- ///
125
+ ///
126
126
/// Note that, just because an unlink call was successful, it is not
127
127
/// guaranteed that a file is immediately deleted (e.g. depending on
128
128
/// platform, other open file descriptors may prevent immediate removal)
129
- ///
129
+ ///
130
130
/// # Errors
131
- ///
131
+ ///
132
132
/// This function will raise an `io_error` condition if the user lacks permissions to
133
133
/// remove the file or if some other filesystem-level error occurs
134
134
pub fn unlink < P : PathLike > ( path : & P ) {
@@ -145,20 +145,20 @@ pub fn unlink<P: PathLike>(path: &P) {
145
145
}
146
146
147
147
/// Create a new, empty directory at the provided path
148
- ///
148
+ ///
149
149
/// # Example
150
- ///
150
+ ///
151
151
/// use std;
152
152
/// use std::path::Path;
153
153
/// use std::rt::io::support::PathLike;
154
154
/// use std::rt::io::file::mkdir;
155
- ///
155
+ ///
156
156
/// let p = &Path("/some/dir");
157
157
/// mkdir(p);
158
158
/// // If we got here, our directory exists! Horray!
159
- ///
159
+ ///
160
160
/// # Errors
161
- ///
161
+ ///
162
162
/// This call will raise an `io_error` condition if the user lacks permissions to make a
163
163
/// new directory at the provided path, or if the directory already exists
164
164
pub fn mkdir < P : PathLike > ( path : & P ) {
@@ -175,20 +175,20 @@ pub fn mkdir<P: PathLike>(path: &P) {
175
175
}
176
176
177
177
/// Remove an existing, empty directory
178
- ///
178
+ ///
179
179
/// # Example
180
- ///
180
+ ///
181
181
/// use std;
182
182
/// use std::path::Path;
183
183
/// use std::rt::io::support::PathLike;
184
184
/// use std::rt::io::file::rmdir;
185
- ///
185
+ ///
186
186
/// let p = &Path("/some/dir");
187
187
/// rmdir(p);
188
188
/// // good riddance, you mean ol' directory
189
- ///
189
+ ///
190
190
/// # Errors
191
- ///
191
+ ///
192
192
/// This call will raise an `io_error` condition if the user lacks permissions to remove the
193
193
/// directory at the provided path, or if the directory isn't empty
194
194
pub fn rmdir < P : PathLike > ( path : & P ) {
@@ -205,21 +205,21 @@ pub fn rmdir<P: PathLike>(path: &P) {
205
205
}
206
206
207
207
/// Get information on the file, directory, etc at the provided path
208
- ///
208
+ ///
209
209
/// Given a `rt::io::support::PathLike`, query the file system to get
210
210
/// information about a file, directory, etc.
211
- ///
211
+ ///
212
212
/// Returns a `Some(std::rt::io::PathInfo)` on success
213
- ///
213
+ ///
214
214
/// # Example
215
- ///
215
+ ///
216
216
/// use std;
217
217
/// use std::path::Path;
218
218
/// use std::rt::io::support::PathLike;
219
219
/// use std::rt::io::file::stat;
220
- ///
220
+ ///
221
221
/// let p = &Path("/some/file/path.txt");
222
- ///
222
+ ///
223
223
/// do io_error::cond.trap(|_| {
224
224
/// // hoo-boy...
225
225
/// }).inside {
@@ -230,13 +230,13 @@ pub fn rmdir<P: PathLike>(path: &P) {
230
230
/// if stat.is_file {
231
231
/// // just imagine the possibilities ...
232
232
/// }
233
- ///
233
+ ///
234
234
/// // the file stream will be closed at the end of this block
235
235
/// }
236
236
/// // ..
237
- ///
237
+ ///
238
238
/// # Errors
239
- ///
239
+ ///
240
240
/// This call will raise an `io_error` condition if the user lacks the requisite
241
241
/// permissions to perform a `stat` call on the given path or if there is no
242
242
/// entry in the filesystem at the provided path.
@@ -325,7 +325,7 @@ impl Seek for FileReader {
325
325
}
326
326
327
327
/// Constrained version of `FileStream` that only exposes write-specific operations.
328
- ///
328
+ ///
329
329
/// Can be retreived via `FileInfo.open_writer()`.
330
330
pub struct FileWriter { priv stream : FileStream }
331
331
@@ -352,15 +352,15 @@ impl Seek for FileWriter {
352
352
}
353
353
354
354
/// Unconstrained file access type that exposes read and write operations
355
- ///
355
+ ///
356
356
/// Can be retreived via `file::open()` and `FileInfo.open_stream()`.
357
- ///
357
+ ///
358
358
/// # Errors
359
- ///
359
+ ///
360
360
/// This type will raise an io_error condition if operations are attempted against
361
361
/// it for which its underlying file descriptor was not configured at creation
362
362
/// time, via the `FileAccess` parameter to `file::open()`.
363
- ///
363
+ ///
364
364
/// For this reason, it is best to use the access-constrained wrappers that are
365
365
/// exposed via `FileInfo.open_reader()` and `FileInfo.open_writer()`.
366
366
pub struct FileStream {
@@ -474,25 +474,25 @@ pub trait FileSystemInfo {
474
474
}
475
475
476
476
/// Represents a file, whose underlying path may or may not be valid
477
- ///
477
+ ///
478
478
/// # Example
479
- ///
479
+ ///
480
480
/// * Check if a file exists, reading from it if so
481
- ///
481
+ ///
482
482
/// use std;
483
483
/// use std::path::Path;
484
484
/// use std::rt::io::file::{FileInfo, FileReader};
485
- ///
485
+ ///
486
486
/// let f = &Path("/some/file/path.txt");
487
487
/// if f.exists() {
488
488
/// let reader = f.open_reader(Open);
489
489
/// let mut mem = [0u8, 8*64000];
490
490
/// reader.read(mem);
491
491
/// // ...
492
492
/// }
493
- ///
493
+ ///
494
494
/// * Is the given path a file?
495
- ///
495
+ ///
496
496
/// let f = get_file_path_from_wherever();
497
497
/// match f.is_file() {
498
498
/// true => doing_something_with_a_file(f),
@@ -567,22 +567,22 @@ impl FileSystemInfo for Path {
567
567
impl FileInfo for Path { }
568
568
569
569
/// Represents a directory, whose underlying path may or may not be valid
570
- ///
570
+ ///
571
571
/// # Example
572
- ///
572
+ ///
573
573
/// * Check if a directory exists, `mkdir`'ing it if not
574
- ///
574
+ ///
575
575
/// use std;
576
576
/// use std::path::Path;
577
577
/// use std::rt::io::file::{DirectoryInfo};
578
- ///
578
+ ///
579
579
/// let dir = &Path("/some/dir");
580
580
/// if !dir.exists() {
581
581
/// dir.mkdir();
582
582
/// }
583
- ///
583
+ ///
584
584
/// * Is the given path a directory? If so, iterate on its contents
585
- ///
585
+ ///
586
586
/// fn visit_dirs(dir: &Path, cb: &fn(&Path)) {
587
587
/// if dir.is_dir() {
588
588
/// let contents = dir.readdir();
0 commit comments