Skip to content

Commit 76128b3

Browse files
committed
Update documentation in windows::fs
1 parent d7df6dc commit 76128b3

File tree

1 file changed

+127
-10
lines changed
  • src/libstd/sys/windows/ext

1 file changed

+127
-10
lines changed

src/libstd/sys/windows/ext/fs.rs

Lines changed: 127 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use path::Path;
1818
use sys;
1919
use sys_common::{AsInnerMut, AsInner};
2020

21-
/// Windows-specific extensions to `File`
21+
/// Windows-specific extensions to [`File`].
22+
///
23+
/// [`File`]: ../../../fs/struct.File.html
2224
#[stable(feature = "file_offset", since = "1.15.0")]
2325
pub trait FileExt {
2426
/// Seeks to a given position and reads a number of bytes.
@@ -103,7 +105,9 @@ impl FileExt for fs::File {
103105
}
104106
}
105107

106-
/// Windows-specific extensions to `OpenOptions`
108+
/// Windows-specific extensions to [`OpenOptions`].
109+
///
110+
/// [`OpenOptions`]: ../../../fs/struct.OpenOptions.html
107111
#[stable(feature = "open_options_ext", since = "1.10.0")]
108112
pub trait OpenOptionsExt {
109113
/// Overrides the `dwDesiredAccess` argument to the call to [`CreateFile`]
@@ -267,42 +271,155 @@ impl OpenOptionsExt for OpenOptions {
267271
}
268272
}
269273

270-
/// Extension methods for `fs::Metadata` to access the raw fields contained
274+
/// Extension methods for [`fs::Metadata`] to access the raw fields contained
271275
/// within.
276+
///
277+
/// The data members that this trait exposes correspond to the members
278+
/// of the [`BY_HANDLE_FILE_INFORMATION`] structure.
279+
///
280+
/// [`fs::Metadata`]: ../../../fs/struct.Metadata.html
281+
/// [`BY_HANDLE_FILE_INFORMATION`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363788.aspx
272282
#[stable(feature = "metadata_ext", since = "1.1.0")]
273283
pub trait MetadataExt {
274284
/// Returns the value of the `dwFileAttributes` field of this metadata.
275285
///
276286
/// This field contains the file system attribute information for a file
277-
/// or directory.
287+
/// or directory. For possible values and their descriptions, see
288+
/// [File Attribute Constants] in the Windows Dev Center.
289+
///
290+
/// # Examples
291+
///
292+
/// ```ignore
293+
/// use std::io;
294+
/// use std::io::prelude::*;
295+
/// use std::fs::File;
296+
/// use std::os::windows::prelude::*;
297+
///
298+
/// # fn foo() -> io::Result<()> {
299+
/// let mut file = File::open("foo.txt")?;
300+
/// let attributes = file.file_attributes();
301+
/// # }
302+
/// ```
303+
///
304+
/// [File Attribute Constants]: https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117.aspx
278305
#[stable(feature = "metadata_ext", since = "1.1.0")]
279306
fn file_attributes(&self) -> u32;
280307

281308
/// Returns the value of the `ftCreationTime` field of this metadata.
282309
///
283-
/// The returned 64-bit value represents the number of 100-nanosecond
284-
/// intervals since January 1, 1601 (UTC).
310+
/// The returned 64-bit value is equivalent to a [`FILETIME`] struct,
311+
/// which represents the number of 100-nanosecond intervals since
312+
/// January 1, 1601 (UTC). The struct is automatically
313+
/// converted to a `u64` value, as that is the recommended way
314+
/// to use it.
315+
///
316+
/// If the underlying filesystem does not support creation time, the
317+
/// returned value is 0.
318+
///
319+
/// # Examples
320+
///
321+
/// ```ignore
322+
/// use std::io;
323+
/// use std::io::prelude::*;
324+
/// use std::fs::File;
325+
/// use std::os::windows::prelude::*;
326+
///
327+
/// # fn foo() -> io::Result<()> {
328+
/// let mut file = File::open("foo.txt")?;
329+
/// let creation_time = file.creation_time();
330+
/// # }
331+
/// ```
332+
///
333+
/// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx
285334
#[stable(feature = "metadata_ext", since = "1.1.0")]
286335
fn creation_time(&self) -> u64;
287336

288337
/// Returns the value of the `ftLastAccessTime` field of this metadata.
289338
///
290-
/// The returned 64-bit value represents the number of 100-nanosecond
291-
/// intervals since January 1, 1601 (UTC).
339+
/// The returned 64-bit value is equivalent to a [`FILETIME`] struct,
340+
/// which represents the number of 100-nanosecond intervals since
341+
/// January 1, 1601 (UTC). The struct is automatically
342+
/// converted to a `u64` value, as that is the recommended way
343+
/// to use it.
344+
///
345+
/// For a file, the value specifies the last time that a file was read
346+
/// from or written to. For a directory, the value specifies when
347+
/// the directory was created. For both files and directories, the
348+
/// specified date is correct, but the time of day is always set to
349+
/// midnight.
350+
///
351+
/// If the underlying filesystem does not support last access time, the
352+
/// returned value is 0.
353+
///
354+
/// # Examples
355+
///
356+
/// ```ignore
357+
/// use std::io;
358+
/// use std::io::prelude::*;
359+
/// use std::fs::File;
360+
/// use std::os::windows::prelude::*;
361+
///
362+
/// # fn foo() -> io::Result<()> {
363+
/// let mut file = File::open("foo.txt")?;
364+
/// let last_access_time = file.last_access_time();
365+
/// # }
366+
/// ```
367+
///
368+
/// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx
292369
#[stable(feature = "metadata_ext", since = "1.1.0")]
293370
fn last_access_time(&self) -> u64;
294371

295372
/// Returns the value of the `ftLastWriteTime` field of this metadata.
296373
///
297-
/// The returned 64-bit value represents the number of 100-nanosecond
298-
/// intervals since January 1, 1601 (UTC).
374+
/// The returned 64-bit value is equivalent to a [`FILETIME`] struct,
375+
/// which represents the number of 100-nanosecond intervals since
376+
/// January 1, 1601 (UTC). The struct is automatically
377+
/// converted to a `u64` value, as that is the recommended way
378+
/// to use it.
379+
///
380+
/// For a file, the value specifies the last time that a file was written
381+
/// to. For a directory, the structure specifies when the directory was
382+
/// created.
383+
///
384+
/// If the underlying filesystem does not support the last write time
385+
/// time, the returned value is 0.
386+
///
387+
/// # Examples
388+
///
389+
/// ```ignore
390+
/// use std::io;
391+
/// use std::io::prelude::*;
392+
/// use std::fs::File;
393+
/// use std::os::windows::prelude::*;
394+
///
395+
/// # fn foo() -> io::Result<()> {
396+
/// let mut file = File::open("foo.txt")?;
397+
/// let last_write_time = file.last_write_time();
398+
/// # }
399+
/// ```
400+
///
401+
/// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx
299402
#[stable(feature = "metadata_ext", since = "1.1.0")]
300403
fn last_write_time(&self) -> u64;
301404

302405
/// Returns the value of the `nFileSize{High,Low}` fields of this
303406
/// metadata.
304407
///
305408
/// The returned value does not have meaning for directories.
409+
///
410+
/// # Examples
411+
///
412+
/// ```ignore
413+
/// use std::io;
414+
/// use std::io::prelude::*;
415+
/// use std::fs::File;
416+
/// use std::os::windows::prelude::*;
417+
///
418+
/// # fn foo() -> io::Result<()> {
419+
/// let mut file = File::open("foo.txt")?;
420+
/// let file_size = file.file_size();
421+
/// # }
422+
/// ```
306423
#[stable(feature = "metadata_ext", since = "1.1.0")]
307424
fn file_size(&self) -> u64;
308425
}

0 commit comments

Comments
 (0)