Commit 9b75bd7
authored
Unrolled build for #149295
Rollup merge of #149295 - kornelski:endian_bytes, r=Mark-Simulacrum
Suggest _bytes versions of endian-converting methods
As pointed out [in this article](https://purplesyringa.moe/blog/ntoh-hton-is-a-bad-api/), the `int.to_be()`/`int.to_le()` functions are technically returning a wrong type, because endian-specific representations of integers and Rust's always-native-endian integers are different things.
I wanted to make the docs state more directly that byte swapping will result in the type having a "wrong" value, but I wasn't sure whether to delve into the special case of palindrome-like values (`0x12343412`) not changing.
I've updated the docs to suggest `{to,from}_[lb]e_bytes()` instead. These methods use `[u8; _]` for endian-specific representations, which is a different type than the native-endian `u16`/`u32`/`u64`, and this is a type-safety improvement.1 file changed
+20
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| 375 | + | |
| 376 | + | |
375 | 377 | | |
376 | 378 | | |
377 | 379 | | |
| |||
402 | 404 | | |
403 | 405 | | |
404 | 406 | | |
| 407 | + | |
| 408 | + | |
405 | 409 | | |
406 | 410 | | |
407 | 411 | | |
| |||
428 | 432 | | |
429 | 433 | | |
430 | 434 | | |
431 | | - | |
| 435 | + | |
432 | 436 | | |
433 | | - | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
434 | 444 | | |
435 | 445 | | |
436 | 446 | | |
| |||
459 | 469 | | |
460 | 470 | | |
461 | 471 | | |
462 | | - | |
| 472 | + | |
463 | 473 | | |
464 | | - | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
465 | 481 | | |
466 | 482 | | |
467 | 483 | | |
| |||
0 commit comments