mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 22:18:33 +00:00
Move docs for !Sync
resources onto the correct trait (#8066)
This commit is contained in:
parent
0918b30e29
commit
ed97c621b8
1 changed files with 32 additions and 32 deletions
|
@ -89,38 +89,6 @@ use std::{
|
|||
/// This will most commonly occur when working with `SystemParam`s generically, as the requirement
|
||||
/// has not been proven to the compiler.
|
||||
///
|
||||
/// # `!Sync` Resources
|
||||
/// A `!Sync` type cannot implement `Resource`. However, it is possible to wrap a `Send` but not `Sync`
|
||||
/// type in [`SyncCell`] or the currently unstable [`Exclusive`] to make it `Sync`. This forces only
|
||||
/// having mutable access (`&mut T` only, never `&T`), but makes it safe to reference across multiple
|
||||
/// threads.
|
||||
///
|
||||
/// This will fail to compile since `RefCell` is `!Sync`.
|
||||
/// ```compile_fail
|
||||
/// # use std::cell::RefCell;
|
||||
/// # use bevy_ecs::system::Resource;
|
||||
///
|
||||
/// #[derive(Resource)]
|
||||
/// struct NotSync {
|
||||
/// counter: RefCell<usize>,
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This will compile since the `RefCell` is wrapped with `SyncCell`.
|
||||
/// ```
|
||||
/// # use std::cell::RefCell;
|
||||
/// # use bevy_ecs::system::Resource;
|
||||
/// use bevy_utils::synccell::SyncCell;
|
||||
///
|
||||
/// #[derive(Resource)]
|
||||
/// struct ActuallySync {
|
||||
/// counter: SyncCell<RefCell<usize>>,
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [`SyncCell`]: bevy_utils::synccell::SyncCell
|
||||
/// [`Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The implementor must ensure the following is true.
|
||||
|
@ -399,6 +367,38 @@ impl_param_set!();
|
|||
/// # schedule.add_systems((read_resource_system, write_resource_system).chain());
|
||||
/// # schedule.run(&mut world);
|
||||
/// ```
|
||||
///
|
||||
/// # `!Sync` Resources
|
||||
/// A `!Sync` type cannot implement `Resource`. However, it is possible to wrap a `Send` but not `Sync`
|
||||
/// type in [`SyncCell`] or the currently unstable [`Exclusive`] to make it `Sync`. This forces only
|
||||
/// having mutable access (`&mut T` only, never `&T`), but makes it safe to reference across multiple
|
||||
/// threads.
|
||||
///
|
||||
/// This will fail to compile since `RefCell` is `!Sync`.
|
||||
/// ```compile_fail
|
||||
/// # use std::cell::RefCell;
|
||||
/// # use bevy_ecs::system::Resource;
|
||||
///
|
||||
/// #[derive(Resource)]
|
||||
/// struct NotSync {
|
||||
/// counter: RefCell<usize>,
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This will compile since the `RefCell` is wrapped with `SyncCell`.
|
||||
/// ```
|
||||
/// # use std::cell::RefCell;
|
||||
/// # use bevy_ecs::system::Resource;
|
||||
/// use bevy_utils::synccell::SyncCell;
|
||||
///
|
||||
/// #[derive(Resource)]
|
||||
/// struct ActuallySync {
|
||||
/// counter: SyncCell<RefCell<usize>>,
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [`SyncCell`]: bevy_utils::synccell::SyncCell
|
||||
/// [`Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html
|
||||
pub trait Resource: Send + Sync + 'static {}
|
||||
|
||||
// SAFETY: Res only reads a single World resource
|
||||
|
|
Loading…
Add table
Reference in a new issue