From e7525cf6200e5b62a4b1a2f3131f68d946fb331e Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Thu, 26 Mar 2015 13:39:23 -0700 Subject: Revise use of conversion traits 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` 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. --- src/libstd/ffi/os_str.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'src/libstd/ffi') diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 5851c6e2998..24844ad0961 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -113,23 +113,9 @@ impl From for OsString { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> From<&'a String> for OsString { - fn from(s: &'a String) -> OsString { - OsString { inner: Buf::from_str(s) } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a> From<&'a str> for OsString { - fn from(s: &'a str) -> OsString { - OsString { inner: Buf::from_str(s) } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a> From<&'a OsStr> for OsString { - fn from(s: &'a OsStr) -> OsString { - OsString { inner: s.inner.to_owned() } +impl<'a, T: ?Sized + AsRef> From<&'a T> for OsString { + fn from(s: &'a T) -> OsString { + s.as_ref().to_os_string() } } -- cgit 1.4.1-3-g733a5