Skip to content

Commit ab5d842

Browse files
ericktgraydon
authored andcommitted
Add PosixPath and WindowsPath constructor fns
1 parent e1a552a commit ab5d842

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/libcore/path.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,22 @@ pub struct WindowsPath {
1717
components: ~[~str],
1818
}
1919

20+
pub pure fn WindowsPath(s: &str) -> WindowsPath {
21+
from_str(s)
22+
}
23+
2024
pub struct PosixPath {
2125
is_absolute: bool,
2226
components: ~[~str],
2327
}
2428

29+
pub pure fn PosixPath(s: &str) -> PosixPath {
30+
from_str(s)
31+
}
32+
2533
pub trait GenericPath {
2634

27-
static pure fn from_str((&str)) -> self;
35+
static pure fn from_str(&str) -> self;
2836

2937
pure fn dirname() -> ~str;
3038
pure fn filename() -> Option<~str>;
@@ -49,15 +57,15 @@ pub type Path = WindowsPath;
4957

5058
#[cfg(windows)]
5159
pub pure fn Path(s: &str) -> Path {
52-
from_str::<WindowsPath>(s)
60+
WindowsPath(s)
5361
}
5462

5563
#[cfg(unix)]
5664
pub type Path = PosixPath;
5765

5866
#[cfg(unix)]
5967
pub pure fn Path(s: &str) -> Path {
60-
from_str::<PosixPath>(s)
68+
PosixPath(s)
6169
}
6270

6371
impl PosixPath : ToStr {
@@ -166,7 +174,7 @@ impl PosixPath : GenericPath {
166174
}
167175

168176
pure fn with_dirname(d: &str) -> PosixPath {
169-
let dpath = from_str::<PosixPath>(d);
177+
let dpath = PosixPath(d);
170178
match self.filename() {
171179
Some(ref f) => dpath.push(*f),
172180
None => move dpath
@@ -365,7 +373,7 @@ impl WindowsPath : GenericPath {
365373
}
366374

367375
pure fn with_dirname(d: &str) -> WindowsPath {
368-
let dpath = from_str::<WindowsPath>(d);
376+
let dpath = WindowsPath(d);
369377
match self.filename() {
370378
Some(ref f) => dpath.push(*f),
371379
None => move dpath
@@ -493,12 +501,12 @@ pub pure fn normalize(components: &[~str]) -> ~[~str] {
493501
#[test]
494502
fn test_double_slash_collapsing()
495503
{
496-
let path = from_str::<PosixPath>("tmp/");
504+
let path = PosixPath("tmp/");
497505
let path = path.push("/hmm");
498506
let path = path.normalize();
499507
assert ~"tmp/hmm" == path.to_str();
500508

501-
let path = from_str::<WindowsPath>("tmp/");
509+
let path = WindowsPath("tmp/");
502510
let path = path.push("/hmm");
503511
let path = path.normalize();
504512
assert ~"tmp\\hmm" == path.to_str();
@@ -507,7 +515,7 @@ fn test_double_slash_collapsing()
507515
mod posix {
508516

509517
#[cfg(test)]
510-
fn mk(s: &str) -> PosixPath { from_str::<PosixPath>(s) }
518+
fn mk(s: &str) -> PosixPath { PosixPath(s) }
511519

512520
#[cfg(test)]
513521
fn t(wp: &PosixPath, s: &str) {
@@ -661,7 +669,7 @@ mod windows {
661669

662670
#[test]
663671
fn test_windows_paths() {
664-
fn mk(s: &str) -> WindowsPath { from_str::<WindowsPath>(s) }
672+
fn mk(s: &str) -> WindowsPath { WindowsPath(s) }
665673
fn t(wp: &WindowsPath, s: &str) {
666674
let ss = wp.to_str();
667675
let sss = str::from_slice(s);
@@ -705,7 +713,7 @@ mod windows {
705713
}
706714

707715
#[cfg(test)]
708-
fn mk(s: &str) -> PosixPath { from_str::<PosixPath>(s) }
716+
fn mk(s: &str) -> PosixPath { PosixPath(s) }
709717

710718
#[test]
711719
fn test_filetype_foo_bar() {

0 commit comments

Comments
 (0)