//! Resources are unique, singleton-like data types that can be accessed from systems and stored in the [`World`](crate::world::World).12// The derive macro for the `Resource` trait3pub use bevy_ecs_macros::Resource;45/// A type that can be inserted into a [`World`] as a singleton.6///7/// You can access resource data in systems using the [`Res`] and [`ResMut`] system parameters8///9/// Only one resource of each type can be stored in a [`World`] at any given time.10///11/// # Examples12///13/// ```14/// # let mut world = World::default();15/// # let mut schedule = Schedule::default();16/// # use bevy_ecs::prelude::*;17/// #[derive(Resource)]18/// struct MyResource { value: u32 }19///20/// world.insert_resource(MyResource { value: 42 });21///22/// fn read_resource_system(resource: Res<MyResource>) {23/// assert_eq!(resource.value, 42);24/// }25///26/// fn write_resource_system(mut resource: ResMut<MyResource>) {27/// assert_eq!(resource.value, 42);28/// resource.value = 0;29/// assert_eq!(resource.value, 0);30/// }31/// # schedule.add_systems((read_resource_system, write_resource_system).chain());32/// # schedule.run(&mut world);33/// ```34///35/// # `!Sync` Resources36/// A `!Sync` type cannot implement `Resource`. However, it is possible to wrap a `Send` but not `Sync`37/// type in [`SyncCell`] or the currently unstable [`Exclusive`] to make it `Sync`. This forces only38/// having mutable access (`&mut T` only, never `&T`), but makes it safe to reference across multiple39/// threads.40///41/// This will fail to compile since `RefCell` is `!Sync`.42/// ```compile_fail43/// # use std::cell::RefCell;44/// # use bevy_ecs::resource::Resource;45///46/// #[derive(Resource)]47/// struct NotSync {48/// counter: RefCell<usize>,49/// }50/// ```51///52/// This will compile since the `RefCell` is wrapped with `SyncCell`.53/// ```54/// # use std::cell::RefCell;55/// # use bevy_ecs::resource::Resource;56/// use bevy_platform::cell::SyncCell;57///58/// #[derive(Resource)]59/// struct ActuallySync {60/// counter: SyncCell<RefCell<usize>>,61/// }62/// ```63///64/// [`Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html65/// [`World`]: crate::world::World66/// [`Res`]: crate::system::Res67/// [`ResMut`]: crate::system::ResMut68/// [`SyncCell`]: bevy_platform::cell::SyncCell69#[diagnostic::on_unimplemented(70message = "`{Self}` is not a `Resource`",71label = "invalid `Resource`",72note = "consider annotating `{Self}` with `#[derive(Resource)]`"73)]74pub trait Resource: Send + Sync + 'static {}757677