Skip to content

Commit db6d154

Browse files
committed
---
yaml --- r: 145949 b: refs/heads/try2 c: eaec8a7 h: refs/heads/master i: 145947: fbc8496 v: v3
1 parent 5011df6 commit db6d154

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: e65d33e9ed3057a6afeaea9bf68519eb758f51ab
8+
refs/heads/try2: eaec8a71322a59eb284cbd5a8d502b6da321df3c
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

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