relax Sized bounds around change detection types (#5917)
# Objective I wanted to run the code ```rust let reflect_resource: ReflectResource = ...; let value: Mut<dyn Reflect> = reflect_resource.reflect(world); value.deref(); // ^ ERROR: deref method doesn't exist because `dyn Reflect` doesnt satisfy `: Sized`. ``` ## Solution Relax `Sized` bounds in all the methods and trait implementations for `Mut` and friends.
This commit is contained in:
parent
ca3fa9dd6f
commit
6f2cc0b30e
@ -46,7 +46,7 @@ pub trait DetectChanges {
|
|||||||
/// The type contained within this smart pointer
|
/// The type contained within this smart pointer
|
||||||
///
|
///
|
||||||
/// For example, for `Res<T>` this would be `T`.
|
/// For example, for `Res<T>` this would be `T`.
|
||||||
type Inner;
|
type Inner: ?Sized;
|
||||||
|
|
||||||
/// Returns `true` if this value was added after the system last ran.
|
/// Returns `true` if this value was added after the system last ran.
|
||||||
fn is_added(&self) -> bool;
|
fn is_added(&self) -> bool;
|
||||||
@ -90,7 +90,7 @@ pub trait DetectChanges {
|
|||||||
|
|
||||||
macro_rules! change_detection_impl {
|
macro_rules! change_detection_impl {
|
||||||
($name:ident < $( $generics:tt ),+ >, $target:ty, $($traits:ident)?) => {
|
($name:ident < $( $generics:tt ),+ >, $target:ty, $($traits:ident)?) => {
|
||||||
impl<$($generics),* $(: $traits)?> DetectChanges for $name<$($generics),*> {
|
impl<$($generics),* : ?Sized $(+ $traits)?> DetectChanges for $name<$($generics),*> {
|
||||||
type Inner = $target;
|
type Inner = $target;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -130,7 +130,7 @@ macro_rules! change_detection_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$($generics),* $(: $traits)?> Deref for $name<$($generics),*> {
|
impl<$($generics),*: ?Sized $(+ $traits)?> Deref for $name<$($generics),*> {
|
||||||
type Target = $target;
|
type Target = $target;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -139,7 +139,7 @@ macro_rules! change_detection_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$($generics),* $(: $traits)?> DerefMut for $name<$($generics),*> {
|
impl<$($generics),* : ?Sized $(+ $traits)?> DerefMut for $name<$($generics),*> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
self.set_changed();
|
self.set_changed();
|
||||||
@ -165,7 +165,7 @@ macro_rules! change_detection_impl {
|
|||||||
|
|
||||||
macro_rules! impl_into_inner {
|
macro_rules! impl_into_inner {
|
||||||
($name:ident < $( $generics:tt ),+ >, $target:ty, $($traits:ident)?) => {
|
($name:ident < $( $generics:tt ),+ >, $target:ty, $($traits:ident)?) => {
|
||||||
impl<$($generics),* $(: $traits)?> $name<$($generics),*> {
|
impl<$($generics),* : ?Sized $(+ $traits)?> $name<$($generics),*> {
|
||||||
/// Consume `self` and return a mutable reference to the
|
/// Consume `self` and return a mutable reference to the
|
||||||
/// contained value while marking `self` as "changed".
|
/// contained value while marking `self` as "changed".
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -179,12 +179,12 @@ macro_rules! impl_into_inner {
|
|||||||
|
|
||||||
macro_rules! impl_debug {
|
macro_rules! impl_debug {
|
||||||
($name:ident < $( $generics:tt ),+ >, $($traits:ident)?) => {
|
($name:ident < $( $generics:tt ),+ >, $($traits:ident)?) => {
|
||||||
impl<$($generics),* $(: $traits)?> std::fmt::Debug for $name<$($generics),*>
|
impl<$($generics),* : ?Sized $(+ $traits)?> std::fmt::Debug for $name<$($generics),*>
|
||||||
where T: std::fmt::Debug
|
where T: std::fmt::Debug
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.debug_tuple(stringify!($name))
|
f.debug_tuple(stringify!($name))
|
||||||
.field(self.value)
|
.field(&self.value)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ pub(crate) struct Ticks<'a> {
|
|||||||
/// Panics when used as a [`SystemParam`](crate::system::SystemParam) if the resource does not exist.
|
/// Panics when used as a [`SystemParam`](crate::system::SystemParam) if the resource does not exist.
|
||||||
///
|
///
|
||||||
/// Use `Option<ResMut<T>>` instead if the resource might not always exist.
|
/// Use `Option<ResMut<T>>` instead if the resource might not always exist.
|
||||||
pub struct ResMut<'a, T: Resource> {
|
pub struct ResMut<'a, T: ?Sized + Resource> {
|
||||||
pub(crate) value: &'a mut T,
|
pub(crate) value: &'a mut T,
|
||||||
pub(crate) ticks: Ticks<'a>,
|
pub(crate) ticks: Ticks<'a>,
|
||||||
}
|
}
|
||||||
@ -241,7 +241,7 @@ impl<'a, T: Resource> From<ResMut<'a, T>> for Mut<'a, T> {
|
|||||||
/// Panics when used as a `SystemParameter` if the resource does not exist.
|
/// Panics when used as a `SystemParameter` if the resource does not exist.
|
||||||
///
|
///
|
||||||
/// Use `Option<NonSendMut<T>>` instead if the resource might not always exist.
|
/// Use `Option<NonSendMut<T>>` instead if the resource might not always exist.
|
||||||
pub struct NonSendMut<'a, T: 'static> {
|
pub struct NonSendMut<'a, T: ?Sized + 'static> {
|
||||||
pub(crate) value: &'a mut T,
|
pub(crate) value: &'a mut T,
|
||||||
pub(crate) ticks: Ticks<'a>,
|
pub(crate) ticks: Ticks<'a>,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user