Skip to content

Commit 087647c

Browse files
committed
motor: Use UTF-8 guarantee for OS strings
1 parent 8f17d23 commit 087647c

File tree

1 file changed

+7
-6
lines changed
  • library/std/src/os/motor

1 file changed

+7
-6
lines changed

library/std/src/os/motor/ffi.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33

44
use crate::ffi::{OsStr, OsString};
55
use crate::sealed::Sealed;
6+
use crate::sys_common::{AsInner, IntoInner};
67

78
/// Motor OS-specific extensions to [`OsString`].
89
///
910
/// This trait is sealed: it cannot be implemented outside the standard library.
1011
/// This is so that future additional methods are not breaking changes.
1112
pub trait OsStringExt: Sealed {
12-
/// Motor OS strings are utf-8, and thus just strings.
13-
fn as_str(&self) -> &str;
13+
/// Yields the underlying UTF-8 string of this [`OsString`].
14+
fn into_string(self) -> String;
1415
}
1516

1617
impl OsStringExt for OsString {
1718
#[inline]
18-
fn as_str(&self) -> &str {
19-
self.to_str().unwrap()
19+
fn into_string(self) -> String {
20+
self.into_inner().inner
2021
}
2122
}
2223

@@ -25,13 +26,13 @@ impl OsStringExt for OsString {
2526
/// This trait is sealed: it cannot be implemented outside the standard library.
2627
/// This is so that future additional methods are not breaking changes.
2728
pub trait OsStrExt: Sealed {
28-
/// Motor OS strings are utf-8, and thus just strings.
29+
/// Gets the underlying UTF-8 string view of the [`OsStr`] slice.
2930
fn as_str(&self) -> &str;
3031
}
3132

3233
impl OsStrExt for OsStr {
3334
#[inline]
3435
fn as_str(&self) -> &str {
35-
self.to_str().unwrap()
36+
&self.as_inner().inner
3637
}
3738
}

0 commit comments

Comments
 (0)