11use bstr:: ByteSlice ;
2+ use gix_fs:: stack:: ToNormalPathComponents ;
23
34use crate :: {
45 bstr:: { BStr , BString } ,
@@ -380,18 +381,29 @@ impl std::ops::Index<std::ops::RangeTo<usize>> for RepositoryPathPuf {
380381
381382///
382383pub mod repository_path_buf {
384+ use gix_fs:: stack:: to_normal_path_components;
385+
383386 /// The error used in [`RepositoryPathPuf`](super::RepositoryPathPuf).
384387 #[ derive( Debug , thiserror:: Error ) ]
385388 #[ allow( missing_docs) ]
386- pub enum Error { }
389+ pub enum Error {
390+ #[ error( transparent) ]
391+ ContainsNonNormalComponents ( #[ from] to_normal_path_components:: Error ) ,
392+ #[ error( transparent) ]
393+ IllegalUtf8 ( #[ from] gix_path:: Utf8Error ) ,
394+ }
387395}
388396
389397impl TryFrom < & str > for RepositoryPathPuf {
390398 type Error = repository_path_buf:: Error ;
391399
392400 fn try_from ( value : & str ) -> Result < Self , Self :: Error > {
393- // TODO
394- // Check whether the documented constraints are met, return `Err` if not.
401+ let path = std:: path:: Path :: new ( value) ;
402+
403+ for component in path. to_normal_path_components ( ) {
404+ component?;
405+ }
406+
395407 Ok ( Self { inner : value. into ( ) } )
396408 }
397409}
@@ -400,8 +412,12 @@ impl TryFrom<&BStr> for RepositoryPathPuf {
400412 type Error = repository_path_buf:: Error ;
401413
402414 fn try_from ( value : & BStr ) -> Result < Self , Self :: Error > {
403- // TODO
404- // Check whether the documented constraints are met, return `Err` if not.
415+ let path: & std:: path:: Path = & gix_path:: try_from_bstr ( value) ?;
416+
417+ for component in path. to_normal_path_components ( ) {
418+ component?;
419+ }
420+
405421 Ok ( Self { inner : value. into ( ) } )
406422 }
407423}
@@ -410,8 +426,12 @@ impl TryFrom<BString> for RepositoryPathPuf {
410426 type Error = repository_path_buf:: Error ;
411427
412428 fn try_from ( value : BString ) -> Result < Self , Self :: Error > {
413- // TODO
414- // Check whether the documented constraints are met, return `Err` if not.
429+ let path: & std:: path:: Path = & gix_path:: try_from_bstr ( & value) ?;
430+
431+ for component in path. to_normal_path_components ( ) {
432+ component?;
433+ }
434+
415435 Ok ( Self { inner : value } )
416436 }
417437}
0 commit comments