mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
ptr
: allow Ptr
and PtrMut
construction for references to values of ?Sized
types (#14479)
# Objective
- Currently `bevy_ptr::{Ptr, PtrMut}` have `From` implementations from
references.
- These implementations impose an implicit `Sized` bound so `bevy_ptr`
types cannot be created from references to slices and trait objects.
- I ran into this trying to use `Ptr<'static>` as an untyped `&'static
dyn Any`, and [had to work around
it](f32b41512c/src/registry.rs (L214-L219)
).
## Solution
- Relax the `Sized` bound on the relevant `From` implementations.
This commit is contained in:
parent
438217035d
commit
6dbc8b8f6f
1 changed files with 2 additions and 2 deletions
|
@ -314,7 +314,7 @@ impl<'a, A: IsAligned> Ptr<'a, A> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T> From<&'a T> for Ptr<'a> {
|
||||
impl<'a, T: ?Sized> From<&'a T> for Ptr<'a> {
|
||||
#[inline]
|
||||
fn from(val: &'a T) -> Self {
|
||||
// SAFETY: The returned pointer has the same lifetime as the passed reference.
|
||||
|
@ -384,7 +384,7 @@ impl<'a, A: IsAligned> PtrMut<'a, A> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T> From<&'a mut T> for PtrMut<'a> {
|
||||
impl<'a, T: ?Sized> From<&'a mut T> for PtrMut<'a> {
|
||||
#[inline]
|
||||
fn from(val: &'a mut T) -> Self {
|
||||
// SAFETY: The returned pointer has the same lifetime as the passed reference.
|
||||
|
|
Loading…
Reference in a new issue