| ... | ... | @@ -1325,6 +1325,12 @@ fn AsBytesReturnType(comptime P: type) type { |
| 1325 | 1325 | const size = usize(@sizeOf(meta.Child(P))); |
| 1326 | 1326 | const alignment = comptime meta.alignment(P); |
| 1327 | 1327 | |
| 1328 | if (alignment == 0) { |
| 1329 | if (comptime trait.isConstPtr(P)) |
| 1330 | return *const [size]u8; |
| 1331 | return *[size]u8; |
| 1332 | } |
| 1333 | |
| 1328 | 1334 | if (comptime trait.isConstPtr(P)) |
| 1329 | 1335 | return *align(alignment) const [size]u8; |
| 1330 | 1336 | return *align(alignment) [size]u8; |
| ... | ... | @@ -1364,6 +1370,10 @@ test "asBytes" { |
| 1364 | 1370 | .d = 0xA1, |
| 1365 | 1371 | }; |
| 1366 | 1372 | testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); |
| 1373 | |
| 1374 | const ZST = struct {}; |
| 1375 | const zero = ZST{}; |
| 1376 | testing.expect(eql(u8, asBytes(&zero), "")); |
| 1367 | 1377 | } |
| 1368 | 1378 | |
| 1369 | 1379 | ///Given any value, returns a copy of its bytes in an array. |