Skip to content

Commit cc57db0

Browse files
committed
Implemented Path::join
1 parent 0c03b92 commit cc57db0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/path/path.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,27 @@ impl Path {
415415
self.inner.iter()
416416
}
417417

418+
/// Creates an owned [`PathBuf`] with `path` adjoined to `self`.
419+
///
420+
/// See [`PathBuf::push`] for more details on what it means to adjoin a path.
421+
///
422+
/// [`PathBuf`]: struct.PathBuf.html
423+
/// [`PathBuf::push`]: struct.PathBuf.html#method.push
424+
///
425+
/// # Examples
426+
///
427+
/// ```
428+
/// use async_std::path::{Path, PathBuf};
429+
///
430+
/// assert_eq!(Path::new("/etc").join("passwd"), PathBuf::from("/etc/passwd"));
431+
/// ```
432+
pub fn join<P: AsRef<Path>>(&self, path: P) -> PathBuf
433+
where
434+
P: std::convert::AsRef<std::path::Path>,
435+
{
436+
self.inner.join(path).into()
437+
}
438+
418439
/// Queries the file system to get information about a file, directory, etc.
419440
///
420441
/// This function will traverse symbolic links to query information about the

0 commit comments

Comments
 (0)