rust/hg-core/src/dirstate_tree/path_with_basename.rs
changeset 47126 ecfe0819ada5
parent 47119 15395fd8ab28
child 47283 2a9ddc8094c7
--- a/rust/hg-core/src/dirstate_tree/path_with_basename.rs	Fri Apr 30 19:33:04 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/path_with_basename.rs	Fri Apr 30 20:21:56 2021 +0200
@@ -1,5 +1,5 @@
 use crate::utils::hg_path::HgPath;
-use std::borrow::Borrow;
+use std::borrow::{Borrow, Cow};
 
 /// Wraps `HgPath` or `HgPathBuf` to make it behave "as" its last path
 /// component, a.k.a. its base name (as in Python’s `os.path.basename`), but
@@ -81,10 +81,17 @@
     }
 }
 
-impl<T: ?Sized + ToOwned> WithBasename<&'_ T> {
-    pub fn to_owned(&self) -> WithBasename<T::Owned> {
+impl<'a> WithBasename<&'a HgPath> {
+    pub fn to_cow_borrowed(self) -> WithBasename<Cow<'a, HgPath>> {
         WithBasename {
-            full_path: self.full_path.to_owned(),
+            full_path: Cow::Borrowed(self.full_path),
+            base_name_start: self.base_name_start,
+        }
+    }
+
+    pub fn to_cow_owned<'b>(self) -> WithBasename<Cow<'b, HgPath>> {
+        WithBasename {
+            full_path: Cow::Owned(self.full_path.to_owned()),
             base_name_start: self.base_name_start,
         }
     }