Skip to content

Commit 6f2f110

Browse files
committed
---
yaml --- r: 82365 b: refs/heads/master c: eaec8a7 h: refs/heads/master i: 82363: 2cc1829 v: v3
1 parent b6e9f71 commit 6f2f110

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: e65d33e9ed3057a6afeaea9bf68519eb758f51ab
2+
refs/heads/master: eaec8a71322a59eb284cbd5a8d502b6da321df3c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
55
refs/heads/try: 70152ff55722878cde684ee6462c14c65f2c4729

trunk/src/libstd/path/mod.rs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,60 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Cross-platform file path handling (re-write)
11+
/*!
12+
13+
Cross-platform path support
14+
15+
This module implements support for two flavors of paths. `PosixPath` represents
16+
a path on any unix-like system, whereas `WindowsPath` represents a path on
17+
Windows. This module also exposes a typedef `Path` which is equal to the
18+
appropriate platform-specific path variant.
19+
20+
Both `PosixPath` and `WindowsPath` implement a trait `GenericPath`, which
21+
contains the set of methods that behave the same for both paths. They each also
22+
implement some methods that could not be expressed in `GenericPath`, yet behave
23+
identically for both path flavors, such as `::from_str()` or
24+
`.component_iter()`.
25+
26+
The three main design goals of this module are 1) to avoid unnecessary
27+
allocation, 2) to behave the same regardless of which flavor of path is being
28+
used, and 3) to support paths that cannot be represented in UTF-8 (as Linux has
29+
no restriction on paths beyond disallowing NUL).
30+
31+
## Usage
32+
33+
Usage of this module is fairly straightforward. Unless writing platform-specific
34+
code, `Path` should be used to refer to the platform-native path, and methods
35+
used should be restricted to those defined in `GenericPath`, and those methods
36+
that are declared identically on both `PosixPath` and `WindowsPath`.
37+
38+
Creation of a path is typically done with either `Path::from_str(some_str)` or
39+
`Path::from_vec(some_vec)`. This path can be modified with `.push()` and
40+
`.pop()` (and other setters). The resulting Path can either be passed to another
41+
API that expects a path, or can be turned into a &[u8] with `.as_vec()` or a
42+
Option<&str> with `.as_str()`. Similarly, attributes of the path can be queried
43+
with methods such as `.filename()`. There are also methods that return a new
44+
path instead of modifying the receiver, such as `.join()` or `.dir_path()`.
45+
46+
When rendering a path to some form of display, there is a method `.display()`
47+
which is compatible with the `format!()` parameter `{}`. This will render the
48+
path as a string, replacing all non-utf8 sequences with the Replacement
49+
Character (U+FFFD). As such it is not suitable for passing to any API that
50+
actually operates on the path; it is only intended for display.
51+
52+
## Example
53+
54+
```rust
55+
let mut path = Path::from_str("/tmp/path");
56+
debug2!("path: {}", path.display());
57+
path.set_filename_str("foo");
58+
path.push_str("bar");
59+
debug2!("new path: {}", path.display());
60+
let b = std::os::path_exists(&path);
61+
debug2!("path exists: {}", b);
62+
```
63+
64+
*/
1265

1366
use container::Container;
1467
use c_str::CString;

0 commit comments

Comments
 (0)