@@ -148,8 +148,9 @@ pub(super) fn write(out: &mut OutFile) {
148
148
149
149
if builtin. ptr_len {
150
150
out. begin_block ( Block :: Namespace ( "repr" ) ) ;
151
+ writeln ! ( out, "template <typename T>" ) ;
151
152
writeln ! ( out, "struct PtrLen final {{" ) ;
152
- writeln ! ( out, " const void *ptr;" ) ;
153
+ writeln ! ( out, " T *ptr;" ) ;
153
154
writeln ! ( out, " size_t len;" ) ;
154
155
writeln ! ( out, "}};" ) ;
155
156
out. end_block ( Block :: Namespace ( "repr" ) ) ;
@@ -163,7 +164,7 @@ pub(super) fn write(out: &mut OutFile) {
163
164
if builtin. rust_str_new_unchecked {
164
165
writeln ! (
165
166
out,
166
- " static Str new_unchecked(repr::PtrLen repr) noexcept {{" ,
167
+ " static Str new_unchecked(repr::PtrLen<const void> repr) noexcept {{" ,
167
168
) ;
168
169
writeln ! ( out, " Str str;" ) ;
169
170
writeln ! ( out, " str.ptr = static_cast<const char *>(repr.ptr);" ) ;
@@ -172,8 +173,8 @@ pub(super) fn write(out: &mut OutFile) {
172
173
writeln ! ( out, " }}" ) ;
173
174
}
174
175
if builtin. rust_str_repr {
175
- writeln ! ( out, " static repr::PtrLen repr(Str str) noexcept {{" ) ;
176
- writeln ! ( out, " return repr::PtrLen{{str.ptr, str.len}};" ) ;
176
+ writeln ! ( out, " static repr::PtrLen<const void> repr(Str str) noexcept {{" ) ;
177
+ writeln ! ( out, " return repr::PtrLen<const void> {{str.ptr, str.len}};" ) ;
177
178
writeln ! ( out, " }}" ) ;
178
179
}
179
180
writeln ! ( out, "}};" ) ;
@@ -187,7 +188,7 @@ pub(super) fn write(out: &mut OutFile) {
187
188
if builtin. rust_slice_new {
188
189
writeln ! (
189
190
out,
190
- " static Slice<T> slice(repr::PtrLen repr) noexcept {{" ,
191
+ " static Slice<T> slice(repr::PtrLen<const void> repr) noexcept {{" ,
191
192
) ;
192
193
writeln ! (
193
194
out,
@@ -196,11 +197,20 @@ pub(super) fn write(out: &mut OutFile) {
196
197
writeln ! ( out, " }}" ) ;
197
198
}
198
199
if builtin. rust_slice_repr {
200
+ writeln ! ( out, " template <typename U = T>" ) ;
201
+ writeln ! (
202
+ out,
203
+ " static typename std::enable_if<std::is_const<U>::value, repr::PtrLen<const void>>::type repr(Slice<T> slice) noexcept {{" ,
204
+ ) ;
205
+ writeln ! ( out, " return repr::PtrLen<const void>{{slice.ptr, slice.len}};" ) ;
206
+ writeln ! ( out, " }}" ) ;
207
+
208
+ writeln ! ( out, " template <typename U = T>" ) ;
199
209
writeln ! (
200
210
out,
201
- " static repr::PtrLen repr(Slice<T> slice) noexcept {{" ,
211
+ " static typename std::enable_if<!std::is_const<U>::value, repr::PtrLen<void>>::type repr(Slice<T> slice) noexcept {{" ,
202
212
) ;
203
- writeln ! ( out, " return repr::PtrLen{{slice.ptr, slice.len}};" ) ;
213
+ writeln ! ( out, " return repr::PtrLen<void> {{slice.ptr, slice.len}};" ) ;
204
214
writeln ! ( out, " }}" ) ;
205
215
}
206
216
writeln ! ( out, "}};" ) ;
@@ -211,7 +221,7 @@ pub(super) fn write(out: &mut OutFile) {
211
221
writeln ! ( out, "template <>" ) ;
212
222
writeln ! ( out, "class impl<Error> final {{" ) ;
213
223
writeln ! ( out, "public:" ) ;
214
- writeln ! ( out, " static Error error(repr::PtrLen repr) noexcept {{" ) ;
224
+ writeln ! ( out, " static Error error(repr::PtrLen<const void> repr) noexcept {{" ) ;
215
225
writeln ! ( out, " Error error;" ) ;
216
226
writeln ! ( out, " error.msg = static_cast<const char *>(repr.ptr);" ) ;
217
227
writeln ! ( out, " error.len = repr.len;" ) ;
0 commit comments