From e3a1a11ed2a1b081b229f1d873114aaf7f5f5137 Mon Sep 17 00:00:00 2001 From: aticu <15schnic@gmail.com> Date: Fri, 17 Jun 2022 16:31:36 +0200 Subject: Implement `TryFrom<&OsStr>` for `&str` --- library/std/src/sys/unix/os_str.rs | 4 ++-- library/std/src/sys/windows/os_str.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'library/std/src/sys') diff --git a/library/std/src/sys/unix/os_str.rs b/library/std/src/sys/unix/os_str.rs index ccbc182240c..b88107479ce 100644 --- a/library/std/src/sys/unix/os_str.rs +++ b/library/std/src/sys/unix/os_str.rs @@ -195,8 +195,8 @@ impl Slice { Slice::from_u8_slice(s.as_bytes()) } - pub fn to_str(&self) -> Option<&str> { - str::from_utf8(&self.inner).ok() + pub fn to_str(&self) -> Result<&str, crate::str::Utf8Error> { + str::from_utf8(&self.inner) } pub fn to_string_lossy(&self) -> Cow<'_, str> { diff --git a/library/std/src/sys/windows/os_str.rs b/library/std/src/sys/windows/os_str.rs index 11883f15022..aca2b739226 100644 --- a/library/std/src/sys/windows/os_str.rs +++ b/library/std/src/sys/windows/os_str.rs @@ -155,7 +155,7 @@ impl Slice { unsafe { mem::transmute(Wtf8::from_str(s)) } } - pub fn to_str(&self) -> Option<&str> { + pub fn to_str(&self) -> Result<&str, crate::str::Utf8Error> { self.inner.as_str() } -- cgit 1.4.1-3-g733a5