Add a cast method to raw pointers.#60601
Conversation
|
r? @Kimundi (rust_highfive has picked a reviewer for you, use r? to override) |
|
@rust-lang/libs how do you feel about adding this? |
This is similar to `NonNull::cast`. Compared to the `as` operator (which has a wide range of meanings depending on the input and output types), a call to this method: * Can only go from a raw pointer to a raw pointer * Cannot change the pointer’s `const`ness … even when the pointed types are inferred based on context.
|
I like the direction of this; it seems readable and particularly amenable for turbofish for added clarity. Moreover, it is constrained which seems like a plus in terms of local reasoning. |
|
Seems plausible to me. We might similarly want methods to go |
I would propose |
|
Or maybe only |
|
Agreed that it seems plausible to me (enough to land as unstable at least) |
|
Seems useful! @bors: r+ |
|
📌 Commit d5e8190 has been approved by |
Add a `cast` method to raw pointers. This is similar to `NonNull::cast`. Compared to the `as` operator (which has a wide range of meanings depending on the input and output types), a call to this method: * Can only go from a raw pointer to a raw pointer * Cannot change the pointer’s `const`ness … even when the pointed types are inferred based on context.
Rollup of 5 pull requests Successful merges: - #60601 (Add a `cast` method to raw pointers.) - #60638 (pin: make the to-module link more visible) - #60647 (cleanup: Remove `DefIndexAddressSpace`) - #60656 (Inline some Cursor calls for slices) - #60657 (Stabilize and re-export core::array in std) Failed merges: r? @ghost
This is similar to
NonNull::cast.Compared to the
asoperator (which has a wide range of meanings depending on the input and output types), a call to this method:constness… even when the pointed types are inferred based on context.