@@ -360,10 +360,23 @@ impl Path {
360360 }
361361
362362 /// Creates a new child of this [`Path`]
363+ #[ deprecated = "use .join() or .clone().join() instead" ]
363364 pub fn child < ' a > ( & self , child : impl Into < PathPart < ' a > > ) -> Self {
364- let raw = match self . raw . is_empty ( ) {
365- true => format ! ( "{}" , child. into( ) . raw) ,
366- false => format ! ( "{}{}{}" , self . raw, DELIMITER , child. into( ) . raw) ,
365+ self . clone ( ) . join ( child)
366+ }
367+
368+ /// Appends a single path segment to this [`Path`]
369+ pub fn join < ' a > ( self , child : impl Into < PathPart < ' a > > ) -> Self {
370+ let child_cow_str = child. into ( ) . raw ;
371+
372+ let raw = if self . raw . is_empty ( ) {
373+ child_cow_str. to_string ( )
374+ } else {
375+ use std:: fmt:: Write ;
376+
377+ let mut raw = self . raw ;
378+ write ! ( raw, "{DELIMITER}{child_cow_str}" ) . expect ( "failed to append to string" ) ;
379+ raw
367380 } ;
368381
369382 Self { raw }
@@ -598,7 +611,7 @@ mod tests {
598611 ) ;
599612
600613 // a longer prefix doesn't match
601- let needle = haystack. child ( "longer now" ) ;
614+ let needle = haystack. clone ( ) . join ( "longer now" ) ;
602615 assert ! (
603616 !haystack. prefix_matches( & needle) ,
604617 "{haystack:?} shouldn't have started with {needle:?}"
@@ -612,7 +625,7 @@ mod tests {
612625 ) ;
613626
614627 // two dir prefix matches
615- let needle = needle. child ( "baz%2Ftest" ) ;
628+ let needle = needle. join ( "baz%2Ftest" ) ;
616629 assert ! (
617630 haystack. prefix_matches( & needle) ,
618631 "{haystack:?} should have started with {needle:?}"
0 commit comments