Skip to content

Commit

Permalink
BREAKING: OsStr/Path methods now use FromUtf8Error
Browse files Browse the repository at this point in the history
Previously, they would just return 'Vec<u8>' as the error type. But a
'FromUtf8Error' gives strictly more information, so we return that
instead.

Closes #52
  • Loading branch information
dylni authored and BurntSushi committed Jul 5, 2022
1 parent 185f55f commit 7aecaf7
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/ext_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,25 +486,22 @@ pub trait ByteVec: Sealed {
/// assert_eq!(os_str, OsStr::new("foo"));
/// ```
#[inline]
fn into_os_string(self) -> Result<OsString, Vec<u8>>
fn into_os_string(self) -> Result<OsString, FromUtf8Error>
where
Self: Sized,
{
#[cfg(unix)]
#[inline]
fn imp(v: Vec<u8>) -> Result<OsString, Vec<u8>> {
fn imp(v: Vec<u8>) -> Result<OsString, FromUtf8Error> {
use std::os::unix::ffi::OsStringExt;

Ok(OsString::from_vec(v))
}

#[cfg(not(unix))]
#[inline]
fn imp(v: Vec<u8>) -> Result<OsString, Vec<u8>> {
match v.into_string() {
Ok(s) => Ok(OsString::from(s)),
Err(err) => Err(err.into_vec()),
}
fn imp(v: Vec<u8>) -> Result<OsString, FromUtf8Error> {
v.into_string().map(OsString::from)
}

imp(self.into_vec())
Expand Down Expand Up @@ -570,7 +567,7 @@ pub trait ByteVec: Sealed {
/// assert_eq!(path.as_os_str(), "foo");
/// ```
#[inline]
fn into_path_buf(self) -> Result<PathBuf, Vec<u8>>
fn into_path_buf(self) -> Result<PathBuf, FromUtf8Error>
where
Self: Sized,
{
Expand Down

0 comments on commit 7aecaf7

Please sign in to comment.