rust/hg-core/src/utils/hg_path.rs
changeset 50378 d27b6fc7c1bf
parent 50376 331a3cbe1c9e
equal deleted inserted replaced
50377:e2c8b30ab4e7 50378:d27b6fc7c1bf
   477     fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T) {
   477     fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T) {
   478         self.inner.extend(iter);
   478         self.inner.extend(iter);
   479     }
   479     }
   480 }
   480 }
   481 
   481 
       
   482 /// Create a new [`OsString`] from types referenceable as [`HgPath`].
       
   483 ///
   482 /// TODO: Once <https://www.mercurial-scm.org/wiki/WindowsUTF8Plan> is
   484 /// TODO: Once <https://www.mercurial-scm.org/wiki/WindowsUTF8Plan> is
   483 /// implemented, these conversion utils will have to work differently depending
   485 /// implemented, these conversion utils will have to work differently depending
   484 /// on the repository encoding: either `UTF-8` or `MBCS`.
   486 /// on the repository encoding: either `UTF-8` or `MBCS`.
   485 
       
   486 pub fn hg_path_to_os_string<P: AsRef<HgPath>>(
   487 pub fn hg_path_to_os_string<P: AsRef<HgPath>>(
   487     hg_path: P,
   488     hg_path: P,
   488 ) -> Result<OsString, HgPathError> {
   489 ) -> Result<OsString, HgPathError> {
   489     hg_path.as_ref().check_state()?;
   490     hg_path.as_ref().check_state()?;
   490     let os_str;
   491     let os_str;
   496     // TODO Handle other platforms
   497     // TODO Handle other platforms
   497     // TODO: convert from WTF8 to Windows MBCS (ANSI encoding).
   498     // TODO: convert from WTF8 to Windows MBCS (ANSI encoding).
   498     Ok(os_str.to_os_string())
   499     Ok(os_str.to_os_string())
   499 }
   500 }
   500 
   501 
       
   502 /// Create a new [`PathBuf`] from types referenceable as [`HgPath`].
   501 pub fn hg_path_to_path_buf<P: AsRef<HgPath>>(
   503 pub fn hg_path_to_path_buf<P: AsRef<HgPath>>(
   502     hg_path: P,
   504     hg_path: P,
   503 ) -> Result<PathBuf, HgPathError> {
   505 ) -> Result<PathBuf, HgPathError> {
   504     Ok(Path::new(&hg_path_to_os_string(hg_path)?).to_path_buf())
   506     Ok(Path::new(&hg_path_to_os_string(hg_path)?).to_path_buf())
   505 }
   507 }
   506 
   508 
       
   509 /// Create a new [`HgPathBuf`] from types referenceable as [`OsStr`].
   507 pub fn os_string_to_hg_path_buf<S: AsRef<OsStr>>(
   510 pub fn os_string_to_hg_path_buf<S: AsRef<OsStr>>(
   508     os_string: S,
   511     os_string: S,
   509 ) -> Result<HgPathBuf, HgPathError> {
   512 ) -> Result<HgPathBuf, HgPathError> {
   510     let buf;
   513     let buf;
   511     #[cfg(unix)]
   514     #[cfg(unix)]
   518 
   521 
   519     buf.check_state()?;
   522     buf.check_state()?;
   520     Ok(buf)
   523     Ok(buf)
   521 }
   524 }
   522 
   525 
       
   526 /// Create a new [`HgPathBuf`] from types referenceable as [`Path`].
   523 pub fn path_to_hg_path_buf<P: AsRef<Path>>(
   527 pub fn path_to_hg_path_buf<P: AsRef<Path>>(
   524     path: P,
   528     path: P,
   525 ) -> Result<HgPathBuf, HgPathError> {
   529 ) -> Result<HgPathBuf, HgPathError> {
   526     let buf;
   530     let buf;
   527     let os_str = path.as_ref().as_os_str();
   531     let os_str = path.as_ref().as_os_str();