@@ -73,40 +73,34 @@ impl<'a> PyStringData<'a> {
73
73
match self {
74
74
Self :: Ucs1 ( data) => match str:: from_utf8 ( data) {
75
75
Ok ( s) => Ok ( Cow :: Borrowed ( s) ) ,
76
- Err ( e) => Err ( crate :: PyErr :: from_value_bound (
77
- PyUnicodeDecodeError :: new_utf8_bound ( py, data, e) ?. into_any ( ) ,
78
- ) ) ,
76
+ Err ( e) => Err ( PyUnicodeDecodeError :: new_utf8_bound ( py, data, e) ?. into ( ) ) ,
79
77
} ,
80
78
Self :: Ucs2 ( data) => match String :: from_utf16 ( data) {
81
79
Ok ( s) => Ok ( Cow :: Owned ( s) ) ,
82
80
Err ( e) => {
83
81
let mut message = e. to_string ( ) . as_bytes ( ) . to_vec ( ) ;
84
82
message. push ( 0 ) ;
85
83
86
- Err ( crate :: PyErr :: from_value_bound (
87
- PyUnicodeDecodeError :: new_bound (
88
- py,
89
- CStr :: from_bytes_with_nul ( b"utf-16\0 " ) . unwrap ( ) ,
90
- self . as_bytes ( ) ,
91
- 0 ..self . as_bytes ( ) . len ( ) ,
92
- CStr :: from_bytes_with_nul ( & message) . unwrap ( ) ,
93
- ) ?
94
- . into_any ( ) ,
95
- ) )
96
- }
97
- } ,
98
- Self :: Ucs4 ( data) => match data. iter ( ) . map ( |& c| std:: char:: from_u32 ( c) ) . collect ( ) {
99
- Some ( s) => Ok ( Cow :: Owned ( s) ) ,
100
- None => Err ( crate :: PyErr :: from_value_bound (
101
- PyUnicodeDecodeError :: new_bound (
84
+ Err ( PyUnicodeDecodeError :: new_bound (
102
85
py,
103
- CStr :: from_bytes_with_nul ( b"utf-32 \0 " ) . unwrap ( ) ,
86
+ CStr :: from_bytes_with_nul ( b"utf-16 \0 " ) . unwrap ( ) ,
104
87
self . as_bytes ( ) ,
105
88
0 ..self . as_bytes ( ) . len ( ) ,
106
- CStr :: from_bytes_with_nul ( b"error converting utf-32 \0 " ) . unwrap ( ) ,
89
+ CStr :: from_bytes_with_nul ( & message ) . unwrap ( ) ,
107
90
) ?
108
- . into_any ( ) ,
109
- ) ) ,
91
+ . into ( ) )
92
+ }
93
+ } ,
94
+ Self :: Ucs4 ( data) => match data. iter ( ) . map ( |& c| std:: char:: from_u32 ( c) ) . collect ( ) {
95
+ Some ( s) => Ok ( Cow :: Owned ( s) ) ,
96
+ None => Err ( PyUnicodeDecodeError :: new_bound (
97
+ py,
98
+ CStr :: from_bytes_with_nul ( b"utf-32\0 " ) . unwrap ( ) ,
99
+ self . as_bytes ( ) ,
100
+ 0 ..self . as_bytes ( ) . len ( ) ,
101
+ CStr :: from_bytes_with_nul ( b"error converting utf-32\0 " ) . unwrap ( ) ,
102
+ ) ?
103
+ . into ( ) ) ,
110
104
} ,
111
105
}
112
106
}
0 commit comments