Skip to content

Commit 7e2b76e

Browse files
committed
motor: Use UTF-8 guarantee for OS strings
1 parent 206ffcc commit 7e2b76e

File tree

1 file changed

+13
-8
lines changed
  • library/std/src/os/motor

1 file changed

+13
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,40 @@
33

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

7-
/// Motor OS-specific extensions to [`OsString`].
8+
/// Motor OSspecific 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+
///
15+
/// OS strings on Motor OS are guaranteed to be UTF-8, so are just strings.
16+
fn into_string(self) -> String;
1417
}
1518

1619
impl OsStringExt for OsString {
1720
#[inline]
18-
fn as_str(&self) -> &str {
19-
self.to_str().unwrap()
21+
fn into_string(self) -> String {
22+
self.into_inner().inner
2023
}
2124
}
2225

23-
/// Motor OS-specific extensions to [`OsString`].
26+
/// Motor OSspecific extensions to [`OsString`].
2427
///
2528
/// This trait is sealed: it cannot be implemented outside the standard library.
2629
/// This is so that future additional methods are not breaking changes.
2730
pub trait OsStrExt: Sealed {
28-
/// Motor OS strings are utf-8, and thus just strings.
31+
/// Gets the underlying UTF-8 string view of the [`OsStr`] slice.
32+
///
33+
/// OS strings on Motor OS are guaranteed to be UTF-8, so are just strings.
2934
fn as_str(&self) -> &str;
3035
}
3136

3237
impl OsStrExt for OsStr {
3338
#[inline]
3439
fn as_str(&self) -> &str {
35-
self.to_str().unwrap()
40+
&self.as_inner().inner
3641
}
3742
}

0 commit comments

Comments
 (0)