Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f675d3

Browse files
committed
feat: Boolean::try_from(OsString) (#450)
This makes getting booleans from the environment easier.
1 parent 0fa676a commit 5f675d3

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

git-config-value/src/boolean.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::OsString;
12
use std::{borrow::Cow, convert::TryFrom, fmt::Display};
23

34
use bstr::{BStr, BString, ByteSlice};
@@ -11,6 +12,16 @@ fn bool_err(input: impl Into<BString>) -> Error {
1112
)
1213
}
1314

15+
impl TryFrom<OsString> for Boolean {
16+
type Error = Error;
17+
18+
fn try_from(value: OsString) -> Result<Self, Self::Error> {
19+
let value = git_path::os_str_into_bstr(&value)
20+
.map_err(|_| Error::new("Illformed UTF-8", std::path::Path::new(&value).display().to_string()))?;
21+
Self::try_from(value)
22+
}
23+
}
24+
1425
impl TryFrom<&BStr> for Boolean {
1526
type Error = Error;
1627

0 commit comments

Comments
 (0)