Skip to content

Commit c1147c6

Browse files
SteveLauCasomers
andauthored
docs: document ptr type casting in CONVENTIONS.md (#2197)
* docs: document ptr type casting in CONVENTIONS.md * rephrase it * rephrase it Co-authored-by: Alan Somers <[email protected]> --------- Co-authored-by: Alan Somers <[email protected]>
1 parent 15fb517 commit c1147c6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

CONVENTIONS.md

+10
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,13 @@ the variable.
8484
[enum]: https://doc.rust-lang.org/reference.html#enumerations
8585
[libc]: https://crates.io/crates/libc/
8686
[std_MaybeUninit]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html
87+
88+
## Pointer type casting
89+
90+
We prefer [`cast()`], [`cast_mut()`] and [`cast_const()`] to cast pointer types
91+
over the `as` keyword because it is much more difficult to accidentally change
92+
type or mutability that way.
93+
94+
[`cast()`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.cast
95+
[`cast_mut()`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.cast_mut
96+
[`cast_const()`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.cast_const

0 commit comments

Comments
 (0)