Skip to content

Commit 645a446

Browse files
committed
feat: add try_os_str_into_bstr(), with Cow<OsStr> as input.
1 parent 65a4e78 commit 645a446

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

gix-path/src/convert.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ pub fn os_string_into_bstring(path: OsString) -> Result<BString, Utf8Error> {
3636
}
3737
}
3838

39+
/// Like [`into_bstr()`], but takes `Cow<OsStr>` as input for a lossless, but fallible, conversion.
40+
pub fn try_os_str_into_bstr(path: Cow<'_, OsStr>) -> Result<Cow<'_, BStr>, Utf8Error> {
41+
match path {
42+
Cow::Borrowed(path) => os_str_into_bstr(path).map(Cow::Borrowed),
43+
Cow::Owned(path) => os_string_into_bstring(path).map(Cow::Owned),
44+
}
45+
}
46+
3947
/// Convert the given path either into its raw bytes on unix or its UTF8 encoded counterpart on windows.
4048
///
4149
/// On windows, if the source Path contains ill-formed, lone surrogates, the UTF-8 conversion will fail

0 commit comments

Comments
 (0)