Using `#[derive(Reflect)]` isn't possible on a struct that isn't Sync.
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
bevy_reflect = "0.8.0"
## What you did
```rust
use bevy_reflect::Reflect;
use std::sync::mpsc::Sender;
// This can't derive `Reflect`, even though the problematic field is explicitly marked as `ignore`.
#[derive(Reflect)]
pub struct Baz {
#[reflect(ignore)]
_ignored: Sender,
}
// And so this can't derive `Reflect` either.
#[derive(Reflect)]
pub struct Foo {
bar: Baz,
}
```
## What went wrong
Using `#[derive(Reflect)]` isn't possible on a struct that isn't Sync, even if all sub-structs should be able to derive `Reflect`.
```
error[E0277]: `std::sync::mpsc::Sender` cannot be shared between threads safely
|
14 | #[derive(Reflect)]
| ^^^^^^^ `std::sync::mpsc::Sender` cannot be shared between threads safely
|
= help: within `Baz`, the trait `std::marker::Sync` is not implemented for `std::sync::mpsc::Sender`
note: required because it appears within the type `ecs::Baz`
|
15 | pub struct Baz {
| ^^^
note: required by a bound in `bevy_reflect::Typed`
|
65 | pub trait Typed: Reflect {
| ^^^^^^^ required by this bound in `bevy_reflect::Typed`
= note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)
```
I was expecting that reflection shouldn't have any requirement that a type be `Sync` or even `Send`.
Even if it _did_ have that requirement, I didn't think it would matter if I explicitly used `#[reflect(ignore)]` on the non-Sync fields, but that didn't help either.
## Additional information
What I expected from the `Reflect` macro was:
- It builds a list of iterable fields that I can walk at runtime.
- If I have a mutable reference to the struct, I can edit those fields mutably at run-time via the mutable reference.
- If I have an immutable reference to the struct, I can read those fields immutably at run-time via the immutable reference.
Contributor guide
Assessment
This issue has not been assessed yet.