Override ToOwned::clone_into for Path and OsStr

The only non-overridden one remaining is the CStr impl, which cannot
be optimized as doing so would break CString's second invariant.
This commit is contained in:
Scott McMurray
2017-04-13 02:48:46 -07:00
parent 9f2abadca2
commit 295bcdb715
3 changed files with 30 additions and 1 deletions

View File

@@ -1322,6 +1322,9 @@ impl ToOwned for Path {
fn to_owned(&self) -> PathBuf {
self.to_path_buf()
}
fn clone_into(&self, target: &mut PathBuf) {
self.inner.clone_into(&mut target.inner);
}
}
#[stable(feature = "rust1", since = "1.0.0")]
@@ -3722,4 +3725,13 @@ mod tests {
assert_eq!(&*boxed, &*path_buf);
assert_eq!(&*path_buf, path);
}
#[test]
fn test_clone_into() {
let mut path_buf = PathBuf::from("supercalifragilisticexpialidocious");
let path = Path::new("short");
path.clone_into(&mut path_buf);
assert_eq!(path, path_buf);
assert!(path_buf.into_os_string().capacity() >= 15);
}
}