Commit 887672f
Improve
# Objective
- Although unsafe, `ThinSlicePtr::get()` doesn't signal that it doesn't
perform bounds checking unless you are familiar with the API.
- `ThinSlicePtr::get()` takes `self`, not `&self`, meaning it consumes
the `ThinSlicePtr` each time `get()` is called. This does not match the
behavior of
[`slice.get()`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.get),
which takes `&self`.
- This small issue was hidden by the fact that `ThinSlicePtr` implements
`Copy`. This isn't a large issue because it all compiles down to the
same machine code, but there's no point to `get()` requiring `self`.
- `ThinSlicePtr` could use better documentation, and could be improved a
little in some areas.
## Solution
- Rename `ThinSlicePtr::get()` to `get_unchecked()`, making the API
mirror
[`slice.get_unchecked()`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.get_unchecked).
The old `get()` is kept as a deprecated method, to be removed in 1.19.0.
- Make the new `slice.get_unchecked()` take `&self` rather than `self`.
- Add more documentation and slightly re-arrange code, while maintaining
original behavior.
## Testing
- Any unintentional changes should be caught by the Rust Compiler and
Miri!
---------
Co-authored-by: François Mockers <francois.mockers@vleue.com>ThinSlicePtr API (#21823)1 parent f663241 commit 887672f
File tree
4 files changed
+82
-22
lines changed- crates
- bevy_ecs/src/query
- bevy_ptr/src
- release-content/migration-guides
4 files changed
+82
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1653 | 1653 | | |
1654 | 1654 | | |
1655 | 1655 | | |
1656 | | - | |
| 1656 | + | |
1657 | 1657 | | |
1658 | 1658 | | |
1659 | 1659 | | |
| |||
1841 | 1841 | | |
1842 | 1842 | | |
1843 | 1843 | | |
1844 | | - | |
| 1844 | + | |
1845 | 1845 | | |
1846 | | - | |
| 1846 | + | |
1847 | 1847 | | |
1848 | | - | |
| 1848 | + | |
1849 | 1849 | | |
1850 | | - | |
| 1850 | + | |
| 1851 | + | |
1851 | 1852 | | |
1852 | 1853 | | |
1853 | 1854 | | |
| |||
2053 | 2054 | | |
2054 | 2055 | | |
2055 | 2056 | | |
2056 | | - | |
| 2057 | + | |
2057 | 2058 | | |
2058 | | - | |
| 2059 | + | |
2059 | 2060 | | |
2060 | | - | |
| 2061 | + | |
2061 | 2062 | | |
2062 | | - | |
| 2063 | + | |
| 2064 | + | |
2063 | 2065 | | |
2064 | 2066 | | |
2065 | 2067 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
850 | 850 | | |
851 | 851 | | |
852 | 852 | | |
853 | | - | |
| 853 | + | |
854 | 854 | | |
855 | 855 | | |
856 | 856 | | |
| |||
1078 | 1078 | | |
1079 | 1079 | | |
1080 | 1080 | | |
1081 | | - | |
| 1081 | + | |
1082 | 1082 | | |
1083 | 1083 | | |
1084 | 1084 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1056 | 1056 | | |
1057 | 1057 | | |
1058 | 1058 | | |
1059 | | - | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
1060 | 1082 | | |
1061 | 1083 | | |
1062 | 1084 | | |
| |||
1065 | 1087 | | |
1066 | 1088 | | |
1067 | 1089 | | |
1068 | | - | |
1069 | | - | |
| 1090 | + | |
1070 | 1091 | | |
1071 | 1092 | | |
| 1093 | + | |
1072 | 1094 | | |
1073 | | - | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
1074 | 1099 | | |
1075 | | - | |
| 1100 | + | |
1076 | 1101 | | |
1077 | | - | |
1078 | | - | |
1079 | | - | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1080 | 1116 | | |
1081 | 1117 | | |
1082 | 1118 | | |
| |||
1091 | 1127 | | |
1092 | 1128 | | |
1093 | 1129 | | |
1094 | | - | |
| 1130 | + | |
| 1131 | + | |
1095 | 1132 | | |
1096 | | - | |
1097 | | - | |
| 1133 | + | |
| 1134 | + | |
1098 | 1135 | | |
1099 | 1136 | | |
1100 | 1137 | | |
| |||
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
0 commit comments