Skip to content

Commit 0783864

Browse files
authored
Merge branch 'rust-osdev:main' into pci_protocol_base
2 parents 6ee1b19 + 0466c50 commit 0783864

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

uefi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
implements `Display`.
1919
- Added `Handle::component_name()` and `Handle::device_path()` to simplify the
2020
common use-case of querying more information about a handle.
21+
- Added `fs::path::Path::join()`.
2122

2223
## Changed
2324
- export all `text::{input, output}::*` types

uefi/src/fs/path/path.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ impl Path {
8585
pub const fn is_empty(&self) -> bool {
8686
self.to_cstr16().is_empty()
8787
}
88+
89+
/// Creates an owned [`PathBuf`] with `path` adjoined to `self`.
90+
#[must_use]
91+
pub fn join<P: AsRef<Self>>(&self, path: P) -> PathBuf {
92+
let mut buf = self.to_path_buf();
93+
buf.push(path);
94+
buf
95+
}
8896
}
8997

9098
impl Display for Path {
@@ -294,4 +302,19 @@ mod tests {
294302
assert_ne!(path1, path3);
295303
assert_ne!(path3, path1);
296304
}
305+
306+
#[test]
307+
fn join() {
308+
let path1 = Path::new(cstr16!(r"a\b"));
309+
let path2 = Path::new(cstr16!(r"c\d"));
310+
let path3 = Path::new(cstr16!(r"a\b\c\d"));
311+
312+
assert_eq!(path1.join(path2), path3.to_path_buf());
313+
314+
let pathbuf1 = path1.to_path_buf();
315+
let pathbuf2 = path2.to_path_buf();
316+
let pathbuf3 = path3.to_path_buf();
317+
318+
assert_eq!(pathbuf1.join(pathbuf2), pathbuf3);
319+
}
297320
}

0 commit comments

Comments
 (0)