Closed Rua closed 4 months ago
Nice stuff, I wish I was allowed to use this more rigorously in my crates :)
ref_as_ptr
is the only weird one of the bunch, relying on coercion seems the nicest to me, typically of the form <*const _>::cast(&foo)
:)
I also prefer <*const T>::cast(&x)
. There are several instances of me doing that in the project already. The nice thing is that it doesn't require the latest stable.
Yup, and coercion already disallows turning a &
in a *mut
(without as
casts).
Where is that cast
function defined? Is it just the pointer method?
It's the fully-qualified syntax to get at the inherent method of the pointer type, yes.
And yet, you're passing it a reference? Surprised that just works.
Yes, it's the auto-coersion from reference to pointer as Marijn pointed out.
Yeah cast()
is only available on pointer types. Instead of doing (&foo as *const T).cast()
, which results in a clippy lint saying that the as
cast can be performed via coercion, we "specify" the left-hand type with the fully-qualified syntax to refer to the cast
method on type *const T
. The alternative let foo: *const T = &foo; ... foo.cast()
might also work, but is typically more obtrusive.
I left a few instances of .map(ptr::from_ref)
. If you'd prefer to replace those too, to bring down the MSRV, I can do that.
I would certainly prefer <*const _>::cast(&x)
over ptr::addr_of!(x).cast()
as well for the sake of consistency. Otherwise I love it!
Just want to say, a lot of changes to code that will disappearâ„¢ when moving to ash' .push_next()
lifetime-safe builders :)
Yeah haha :3
This enables and fixes the following Clippy lints:
borrow_as_ptr
, fixed withptr::addr_of!
andptr::addr_of_mut!
ptr_as_ptr
, fixed withptr::cast
ptr_cast_constness
, fixed withptr::cast_const
andptr::cast_mut
ref_as_ptr
, fixed withptr::from_ref
andptr::from_mut
. This lint isn't stable yet, so I left it disabled, but fixed all the instances that are reported by nightly Clippy.I think there should be no more raw pointer casts left using
as
at all now, they should all be explicitly marked as above.