@@ -386,11 +386,16 @@ pub struct String {
386386/// assert_eq!(vec![0, 159], value.unwrap_err().into_bytes());
387387/// ```
388388#[ stable( feature = "rust1" , since = "1.0.0" ) ]
389+ #[ rustc_has_incoherent_inherent_impls]
389390#[ cfg_attr( not( no_global_oom_handling) , derive( Clone ) ) ]
390391#[ derive( Debug , PartialEq , Eq ) ]
391- pub struct FromUtf8Error {
392- bytes : Vec < u8 > ,
393- error : Utf8Error ,
392+ pub struct FromUtf8Error < Input = Vec < u8 > > {
393+ #[ doc( hidden) ]
394+ #[ unstable( feature = "from_utf8_error_internals" , issue = "none" ) ]
395+ pub input : Input ,
396+ #[ doc( hidden) ]
397+ #[ unstable( feature = "from_utf8_error_internals" , issue = "none" ) ]
398+ pub error : Utf8Error ,
394399}
395400
396401/// A possible error value when converting a `String` from a UTF-16 byte slice.
@@ -560,7 +565,7 @@ impl String {
560565 pub fn from_utf8 ( vec : Vec < u8 > ) -> Result < String , FromUtf8Error > {
561566 match str:: from_utf8 ( & vec) {
562567 Ok ( ..) => Ok ( String { vec } ) ,
563- Err ( e) => Err ( FromUtf8Error { bytes : vec, error : e } ) ,
568+ Err ( e) => Err ( FromUtf8Error { input : vec, error : e } ) ,
564569 }
565570 }
566571
@@ -2224,7 +2229,7 @@ impl FromUtf8Error {
22242229 #[ must_use]
22252230 #[ stable( feature = "from_utf8_error_as_bytes" , since = "1.26.0" ) ]
22262231 pub fn as_bytes ( & self ) -> & [ u8 ] {
2227- & self . bytes [ ..]
2232+ & self . input [ ..]
22282233 }
22292234
22302235 /// Converts the bytes into a `String` lossily, substituting invalid UTF-8
@@ -2251,19 +2256,19 @@ impl FromUtf8Error {
22512256 const REPLACEMENT : & str = "\u{FFFD} " ;
22522257
22532258 let mut res = {
2254- let mut v = Vec :: with_capacity ( self . bytes . len ( ) ) ;
2259+ let mut v = Vec :: with_capacity ( self . input . len ( ) ) ;
22552260
22562261 // `Utf8Error::valid_up_to` returns the maximum index of validated
22572262 // UTF-8 bytes. Copy the valid bytes into the output buffer.
2258- v. extend_from_slice ( & self . bytes [ ..self . error . valid_up_to ( ) ] ) ;
2263+ v. extend_from_slice ( & self . input [ ..self . error . valid_up_to ( ) ] ) ;
22592264
22602265 // SAFETY: This is safe because the only bytes present in the buffer
22612266 // were validated as UTF-8 by the call to `String::from_utf8` which
22622267 // produced this `FromUtf8Error`.
22632268 unsafe { String :: from_utf8_unchecked ( v) }
22642269 } ;
22652270
2266- let iter = self . bytes [ self . error . valid_up_to ( ) ..] . utf8_chunks ( ) ;
2271+ let iter = self . input [ self . error . valid_up_to ( ) ..] . utf8_chunks ( ) ;
22672272
22682273 for chunk in iter {
22692274 res. push_str ( chunk. valid ( ) ) ;
@@ -2294,9 +2299,11 @@ impl FromUtf8Error {
22942299 #[ must_use = "`self` will be dropped if the result is not used" ]
22952300 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
22962301 pub fn into_bytes ( self ) -> Vec < u8 > {
2297- self . bytes
2302+ self . input
22982303 }
2304+ }
22992305
2306+ impl < T > FromUtf8Error < T > {
23002307 /// Fetch a `Utf8Error` to get more details about the conversion failure.
23012308 ///
23022309 /// The [`Utf8Error`] type provided by [`std::str`] represents an error that may
0 commit comments