rust/hg-core/src/dirstate_tree/path_with_basename.rs
changeset 47126 ecfe0819ada5
parent 47119 15395fd8ab28
child 47283 2a9ddc8094c7
equal deleted inserted replaced
47125:9be618452c3b 47126:ecfe0819ada5
     1 use crate::utils::hg_path::HgPath;
     1 use crate::utils::hg_path::HgPath;
     2 use std::borrow::Borrow;
     2 use std::borrow::{Borrow, Cow};
     3 
     3 
     4 /// Wraps `HgPath` or `HgPathBuf` to make it behave "as" its last path
     4 /// Wraps `HgPath` or `HgPathBuf` to make it behave "as" its last path
     5 /// component, a.k.a. its base name (as in Python’s `os.path.basename`), but
     5 /// component, a.k.a. its base name (as in Python’s `os.path.basename`), but
     6 /// also allow recovering the full path.
     6 /// also allow recovering the full path.
     7 ///
     7 ///
    79     fn cmp(&self, other: &Self) -> std::cmp::Ordering {
    79     fn cmp(&self, other: &Self) -> std::cmp::Ordering {
    80         self.base_name().cmp(other.base_name())
    80         self.base_name().cmp(other.base_name())
    81     }
    81     }
    82 }
    82 }
    83 
    83 
    84 impl<T: ?Sized + ToOwned> WithBasename<&'_ T> {
    84 impl<'a> WithBasename<&'a HgPath> {
    85     pub fn to_owned(&self) -> WithBasename<T::Owned> {
    85     pub fn to_cow_borrowed(self) -> WithBasename<Cow<'a, HgPath>> {
    86         WithBasename {
    86         WithBasename {
    87             full_path: self.full_path.to_owned(),
    87             full_path: Cow::Borrowed(self.full_path),
       
    88             base_name_start: self.base_name_start,
       
    89         }
       
    90     }
       
    91 
       
    92     pub fn to_cow_owned<'b>(self) -> WithBasename<Cow<'b, HgPath>> {
       
    93         WithBasename {
       
    94             full_path: Cow::Owned(self.full_path.to_owned()),
    88             base_name_start: self.base_name_start,
    95             base_name_start: self.base_name_start,
    89         }
    96         }
    90     }
    97     }
    91 }
    98 }
    92 
    99