@@ -1053,84 +1053,6 @@ impl AsRef<CStr> for CString {
1053
1053
}
1054
1054
}
1055
1055
1056
- #[ cfg( bootstrap) ]
1057
- #[ doc( hidden) ]
1058
- #[ unstable( feature = "cstr_internals" , issue = "none" ) ]
1059
- pub trait CStrExt {
1060
- /// Converts a `CStr` into a <code>[Cow]<[str]></code>.
1061
- ///
1062
- /// If the contents of the `CStr` are valid UTF-8 data, this
1063
- /// function will return a <code>[Cow]::[Borrowed]\(&[str])</code>
1064
- /// with the corresponding <code>&[str]</code> slice. Otherwise, it will
1065
- /// replace any invalid UTF-8 sequences with
1066
- /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a
1067
- /// <code>[Cow]::[Owned]\(&[str])</code> with the result.
1068
- ///
1069
- /// [str]: prim@str "str"
1070
- /// [Borrowed]: Cow::Borrowed
1071
- /// [Owned]: Cow::Owned
1072
- /// [U+FFFD]: crate::char::REPLACEMENT_CHARACTER "std::char::REPLACEMENT_CHARACTER"
1073
- ///
1074
- /// # Examples
1075
- ///
1076
- /// Calling `to_string_lossy` on a `CStr` containing valid UTF-8:
1077
- ///
1078
- /// ```
1079
- /// use std::borrow::Cow;
1080
- /// use std::ffi::CStr;
1081
- ///
1082
- /// let cstr = CStr::from_bytes_with_nul(b"Hello World\0")
1083
- /// .expect("CStr::from_bytes_with_nul failed");
1084
- /// assert_eq!(cstr.to_string_lossy(), Cow::Borrowed("Hello World"));
1085
- /// ```
1086
- ///
1087
- /// Calling `to_string_lossy` on a `CStr` containing invalid UTF-8:
1088
- ///
1089
- /// ```
1090
- /// use std::borrow::Cow;
1091
- /// use std::ffi::CStr;
1092
- ///
1093
- /// let cstr = CStr::from_bytes_with_nul(b"Hello \xF0\x90\x80World\0")
1094
- /// .expect("CStr::from_bytes_with_nul failed");
1095
- /// assert_eq!(
1096
- /// cstr.to_string_lossy(),
1097
- /// Cow::Owned(String::from("Hello �World")) as Cow<'_, str>
1098
- /// );
1099
- /// ```
1100
- #[ must_use = "this returns the result of the operation, \
1101
- without modifying the original"]
1102
- #[ stable( feature = "cstr_to_str" , since = "1.4.0" ) ]
1103
- fn to_string_lossy ( & self ) -> Cow < ' _ , str > ;
1104
-
1105
- /// Converts a <code>[Box]<[CStr]></code> into a [`CString`] without copying or allocating.
1106
- ///
1107
- /// # Examples
1108
- ///
1109
- /// ```
1110
- /// use std::ffi::CString;
1111
- ///
1112
- /// let c_string = CString::new(b"foo".to_vec()).expect("CString::new failed");
1113
- /// let boxed = c_string.into_boxed_c_str();
1114
- /// assert_eq!(boxed.into_c_string(), CString::new("foo").expect("CString::new failed"));
1115
- /// ```
1116
- #[ must_use = "`self` will be dropped if the result is not used" ]
1117
- #[ stable( feature = "into_boxed_c_str" , since = "1.20.0" ) ]
1118
- fn into_c_string ( self : Box < Self > ) -> CString ;
1119
- }
1120
-
1121
- #[ cfg( bootstrap) ]
1122
- #[ unstable( feature = "cstr_internals" , issue = "none" ) ]
1123
- impl CStrExt for CStr {
1124
- fn to_string_lossy ( & self ) -> Cow < ' _ , str > {
1125
- String :: from_utf8_lossy ( self . to_bytes ( ) )
1126
- }
1127
-
1128
- fn into_c_string ( self : Box < Self > ) -> CString {
1129
- CString :: from ( self )
1130
- }
1131
- }
1132
-
1133
- #[ cfg( not( bootstrap) ) ]
1134
1056
#[ cfg( not( test) ) ]
1135
1057
impl CStr {
1136
1058
/// Converts a `CStr` into a <code>[Cow]<[str]></code>.
0 commit comments