Skip to content

Commit 379dce1

Browse files
committed
core: Document core::path::GenericPath's trait methods
1 parent 7b7a0fc commit 379dce1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/libcore/path.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,71 @@ pub fn PosixPath(s: &str) -> PosixPath {
4444
}
4545

4646
pub trait GenericPath {
47+
/// Converts a string to a Path
4748
fn from_str(&str) -> Self;
4849

50+
/// Returns the directory component of `self`, as a string
4951
fn dirname(&self) -> ~str;
52+
/// Returns the file component of `self`, as a string option.
53+
/// Returns None if `self` names a directory.
5054
fn filename(&self) -> Option<~str>;
55+
/// Returns the stem of the file component of `self`, as a string option.
56+
/// The stem is the slice of a filename starting at 0 and ending just before
57+
/// the last '.' in the name.
58+
/// Returns None if `self` names a directory.
5159
fn filestem(&self) -> Option<~str>;
60+
/// Returns the type of the file component of `self`, as a string option.
61+
/// The file type is the slice of a filename starting just after the last
62+
/// '.' in the name and ending at the last index in the filename.
63+
/// Returns None if `self` names a directory.
5264
fn filetype(&self) -> Option<~str>;
5365

66+
/// Returns a new path consisting of `self` with the parent directory component replaced
67+
/// with the given string.
5468
fn with_dirname(&self, (&str)) -> Self;
69+
/// Returns a new path consisting of `self` with the file component replaced
70+
/// with the given string.
5571
fn with_filename(&self, (&str)) -> Self;
72+
/// Returns a new path consisting of `self` with the file stem replaced
73+
/// with the given string.
5674
fn with_filestem(&self, (&str)) -> Self;
75+
/// Returns a new path consisting of `self` with the file type replaced
76+
/// with the given string.
5777
fn with_filetype(&self, (&str)) -> Self;
5878

79+
/// Returns the directory component of `self`, as a new path.
80+
/// If `self` has no parent, returns `self`.
5981
fn dir_path(&self) -> Self;
82+
/// Returns the file component of `self`, as a new path.
83+
/// If `self` names a directory, returns the empty path.
6084
fn file_path(&self) -> Self;
6185

86+
/// Returns a new Path whose parent directory is `self` and whose
87+
/// file component is the given string.
6288
fn push(&self, (&str)) -> Self;
89+
/// Returns a new Path consisting of the given path, made relative to `self`.
6390
fn push_rel(&self, (&Self)) -> Self;
91+
/// Returns a new Path consisting of the path given by the given vector
92+
/// of strings, relative to `self`.
6493
fn push_many(&self, (&[~str])) -> Self;
94+
/// Identical to `dir_path` except in the case where `self` has only one
95+
/// component. In this case, `pop` returns the empty path.
6596
fn pop(&self) -> Self;
6697

98+
/// The same as `push_rel`, except that the directory argument must not
99+
/// contain directory separators in any of its components.
67100
fn unsafe_join(&self, (&Self)) -> Self;
101+
/// On Unix, always returns false. On Windows, returns true iff `self`'s
102+
/// file stem is one of: `con` `aux` `com1` `com2` `com3` `com4`
103+
/// `lpt1` `lpt2` `lpt3` `prn` `nul`
68104
fn is_restricted(&self) -> bool;
69105

106+
/// Returns a new path that names the same file as `self`, without containing
107+
/// any '.', '..', or empty components. On Windows, uppercases the drive letter
108+
/// as well.
70109
fn normalize(&self) -> Self;
71110

111+
/// Returns `true` if `self` is an absolute path.
72112
fn is_absolute(&self) -> bool;
73113
}
74114

0 commit comments

Comments
 (0)