From d5917cfdc3feac5f0e1aa4d992f7210716aa385c Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Mon, 20 Nov 2023 16:41:07 +0800 Subject: [PATCH 1/3] docs: document ptr type casting in CONVENTIONS.md --- CONVENTIONS.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 2461085eb6..bd1b86bc50 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -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 way more easier to change both type and +mutability accidentally. + +[`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 From 8a185f3d3e4b50e7e07d5d3941f0eb4f804e51ef Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Thu, 23 Nov 2023 09:18:26 +0800 Subject: [PATCH 2/3] rephrase it --- CONVENTIONS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index bd1b86bc50..fb31e788d4 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -88,8 +88,8 @@ the variable. ## Pointer type casting We prefer [`cast()`], [`cast_mut()`] and [`cast_const()`] to cast pointer types -over the `as` keyword because it is way more easier to change both type and -mutability accidentally. +over the `as` keyword because they are much more difficult to change both type +and mutability accidentally. [`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 From 26bd9bd48e5931f28b696685c2f757342f24e0cf Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Thu, 23 Nov 2023 10:36:40 +0800 Subject: [PATCH 3/3] rephrase it Co-authored-by: Alan Somers --- CONVENTIONS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index fb31e788d4..695d3d9aa8 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -88,8 +88,8 @@ the variable. ## 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. +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