|
3 | 3 |
|
4 | 4 | use crate::ffi::{OsStr, OsString}; |
5 | 5 | use crate::sealed::Sealed; |
| 6 | +use crate::sys_common::{AsInner, IntoInner}; |
6 | 7 |
|
7 | | -/// Motor OS-specific extensions to [`OsString`]. |
| 8 | +/// Motor OS–specific extensions to [`OsString`]. |
8 | 9 | /// |
9 | 10 | /// This trait is sealed: it cannot be implemented outside the standard library. |
10 | 11 | /// This is so that future additional methods are not breaking changes. |
11 | 12 | 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; |
14 | 17 | } |
15 | 18 |
|
16 | 19 | impl OsStringExt for OsString { |
17 | 20 | #[inline] |
18 | | - fn as_str(&self) -> &str { |
19 | | - self.to_str().unwrap() |
| 21 | + fn into_string(self) -> String { |
| 22 | + self.into_inner().inner |
20 | 23 | } |
21 | 24 | } |
22 | 25 |
|
23 | | -/// Motor OS-specific extensions to [`OsString`]. |
| 26 | +/// Motor OS–specific extensions to [`OsString`]. |
24 | 27 | /// |
25 | 28 | /// This trait is sealed: it cannot be implemented outside the standard library. |
26 | 29 | /// This is so that future additional methods are not breaking changes. |
27 | 30 | 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. |
29 | 34 | fn as_str(&self) -> &str; |
30 | 35 | } |
31 | 36 |
|
32 | 37 | impl OsStrExt for OsStr { |
33 | 38 | #[inline] |
34 | 39 | fn as_str(&self) -> &str { |
35 | | - self.to_str().unwrap() |
| 40 | + &self.as_inner().inner |
36 | 41 | } |
37 | 42 | } |
0 commit comments