diff options
| author | Aaron Turon <aturon@mozilla.com> | 2015-03-26 13:39:23 -0700 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2015-03-26 13:54:48 -0700 |
| commit | e7525cf6200e5b62a4b1a2f3131f68d946fb331e (patch) | |
| tree | 165561491041bb90c0b19df6c22d72f615da1251 /src/libcore | |
| parent | 557d4346a26266d2eb13f6b0adf106b8873b0da1 (diff) | |
| download | rust-e7525cf6200e5b62a4b1a2f3131f68d946fb331e.tar.gz rust-e7525cf6200e5b62a4b1a2f3131f68d946fb331e.zip | |
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<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/libcore')
| -rw-r--r-- | src/libcore/convert.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 65a226d37cb..21f9b1f5513 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -69,6 +69,14 @@ impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a mut T where T: AsRef<U> { } } +// FIXME (#23442): replace the above impls for &/&mut with the following more general one: +// // As lifts over Deref +// impl<D: ?Sized + Deref, U: ?Sized> AsRef<U> for D where D::Target: AsRef<U> { +// fn as_ref(&self) -> &U { +// self.deref().as_ref() +// } +// } + // AsMut implies Into impl<'a, T: ?Sized, U: ?Sized> Into<&'a mut U> for &'a mut T where T: AsMut<U> { fn into(self) -> &'a mut U { @@ -83,6 +91,14 @@ impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T where T: AsMut<U> { } } +// FIXME (#23442): replace the above impl for &mut with the following more general one: +// // AsMut lifts over DerefMut +// impl<D: ?Sized + Deref, U: ?Sized> AsMut<U> for D where D::Target: AsMut<U> { +// fn as_mut(&mut self) -> &mut U { +// self.deref_mut().as_mut() +// } +// } + // From implies Into impl<T, U> Into<U> for T where U: From<T> { fn into(self) -> U { |
