summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/unix/os_str.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/unix/os_str.rs')
-rw-r--r--library/std/src/sys/unix/os_str.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/library/std/src/sys/unix/os_str.rs b/library/std/src/sys/unix/os_str.rs
index 488217f39..f7333fd5a 100644
--- a/library/std/src/sys/unix/os_str.rs
+++ b/library/std/src/sys/unix/os_str.rs
@@ -193,17 +193,22 @@ impl Buf {
impl Slice {
#[inline]
- fn from_u8_slice(s: &[u8]) -> &Slice {
+ pub fn as_os_str_bytes(&self) -> &[u8] {
+ &self.inner
+ }
+
+ #[inline]
+ pub unsafe fn from_os_str_bytes_unchecked(s: &[u8]) -> &Slice {
unsafe { mem::transmute(s) }
}
#[inline]
pub fn from_str(s: &str) -> &Slice {
- Slice::from_u8_slice(s.as_bytes())
+ unsafe { Slice::from_os_str_bytes_unchecked(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> {