Skip to content

Commit

Permalink
docs: document ptr type casting in CONVENTIONS.md (#2197)
Browse files Browse the repository at this point in the history
* docs: document ptr type casting in CONVENTIONS.md

* rephrase it

* rephrase it

Co-authored-by: Alan Somers <asomers@gmail.com>

---------

Co-authored-by: Alan Somers <asomers@gmail.com>
  • Loading branch information
SteveLauC and asomers authored Nov 23, 2023
1 parent 15fb517 commit c1147c6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,13 @@ the variable.
[enum]: https://doc.rust-lang.org/reference.html#enumerations
[libc]: https://crates.io/crates/libc/
[std_MaybeUninit]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html

## Pointer type casting

We prefer [`cast()`], [`cast_mut()`] and [`cast_const()`] to cast pointer types
over the `as` keyword because it is much more difficult to accidentally change
type or mutability that way.

[`cast()`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.cast
[`cast_mut()`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.cast_mut
[`cast_const()`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.cast_const

0 comments on commit c1147c6

Please sign in to comment.