33
44use crate :: ffi:: { OsStr , OsString } ;
55use 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.
1112pub 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
1617impl 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.
2728pub 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
3233impl 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