Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: document ptr type casting in CONVENTIONS.md #2197

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 they are much more difficult to change both type
and mutability accidentally.
SteveLauC marked this conversation as resolved.
Show resolved Hide resolved

[`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