diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-27 10:07:49 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-27 10:07:49 -0700 |
| commit | 7d79a4facd6cd26ff06d99ef4bbb2b35003de28e (patch) | |
| tree | 7de48d79407b29b20376345a1f8c9623449b2ab3 /src/libstd/path.rs | |
| parent | 55c398d651e6b3e4f469325a35e029059ce36f1e (diff) | |
| parent | e7525cf6200e5b62a4b1a2f3131f68d946fb331e (diff) | |
| download | rust-7d79a4facd6cd26ff06d99ef4bbb2b35003de28e.tar.gz rust-7d79a4facd6cd26ff06d99ef4bbb2b35003de28e.zip | |
rollup merge of #23753: aturon/revise-convert
This commit revises `path` and `os_str` to use blanket impls for `From` on reference types. This both cuts down on the number of required impls, and means that you can pass through e.g. `T: AsRef<OsStr>` to `PathBuf::from` without an intermediate call to `as_ref`. It also makes a FIXME note for later generalizing the blanket impls for `AsRef` and `AsMut` to use `Deref`/`DerefMut`, once it is possible to do so.
Diffstat (limited to 'src/libstd/path.rs')
| -rw-r--r-- | src/libstd/path.rs | 40 |
1 files changed, 6 insertions, 34 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 50f79967f55..58d3ae9f7cf 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1038,23 +1038,16 @@ impl PathBuf { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> From<&'a Path> for PathBuf { - fn from(s: &'a Path) -> PathBuf { - s.to_path_buf() +impl<'a, T: ?Sized + AsRef<OsStr>> From<&'a T> for PathBuf { + fn from(s: &'a T) -> PathBuf { + PathBuf::from(s.as_ref().to_os_string()) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> From<&'a str> for PathBuf { - fn from(s: &'a str) -> PathBuf { - PathBuf::from(OsString::from(s)) - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a> From<&'a String> for PathBuf { - fn from(s: &'a String) -> PathBuf { - PathBuf::from(OsString::from(s)) +impl From<OsString> for PathBuf { + fn from(s: OsString) -> PathBuf { + PathBuf { inner: s } } } @@ -1066,27 +1059,6 @@ impl From<String> for PathBuf { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> From<&'a OsStr> for PathBuf { - fn from(s: &'a OsStr) -> PathBuf { - PathBuf::from(OsString::from(s)) - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a> From<&'a OsString> for PathBuf { - fn from(s: &'a OsString) -> PathBuf { - PathBuf::from(s.to_os_string()) - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl From<OsString> for PathBuf { - fn from(s: OsString) -> PathBuf { - PathBuf { inner: s } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] impl<P: AsRef<Path>> iter::FromIterator<P> for PathBuf { fn from_iter<I: IntoIterator<Item = P>>(iter: I) -> PathBuf { let mut buf = PathBuf::new(); |
