Skip to content

Commit 71100a0

Browse files
committed
---
yaml --- r: 83133 b: refs/heads/auto c: eaec8a7 h: refs/heads/master i: 83131: 3bb617e v: v3
1 parent 6d8f5b5 commit 71100a0

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
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: e65d33e9ed3057a6afeaea9bf68519eb758f51ab
16+
refs/heads/auto: eaec8a71322a59eb284cbd5a8d502b6da321df3c
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/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)