Resource

Trait Resource 

Source
pub trait Resource:
    Send
    + Sync
    + 'static { }
Expand description

A type that can be inserted into a World as a singleton.

You can access resource data in systems using the Res and ResMut system parameters

Only one resource of each type can be stored in a World at any given time.

§Examples

#[derive(Resource)]
struct MyResource { value: u32 }

world.insert_resource(MyResource { value: 42 });

fn read_resource_system(resource: Res<MyResource>) {
    assert_eq!(resource.value, 42);
}

fn write_resource_system(mut resource: ResMut<MyResource>) {
    assert_eq!(resource.value, 42);
    resource.value = 0;
    assert_eq!(resource.value, 0);
}

Implementations on Foreign Types§

Source§

impl Resource for TimeUpdateStrategy
where TimeUpdateStrategy: Send + Sync + 'static,

Source§

impl Resource for ScheduleRunnerSettings
where ScheduleRunnerSettings: Send + Sync + 'static,

Source§

impl Resource for FrameCount
where FrameCount: Send + Sync + 'static,

Source§

impl Resource for Diagnostics
where Diagnostics: Send + Sync + 'static,

Source§

impl Resource for GamepadSettings
where GamepadSettings: Send + Sync + 'static,

Source§

impl Resource for FixedTimesteps
where FixedTimesteps: Send + Sync + 'static,

Source§

impl Resource for TimeReceiver
where TimeReceiver: Send + Sync + 'static,

Source§

impl Resource for TimeSender
where TimeSender: Send + Sync + 'static,

Source§

impl<T> Resource for ReportHierarchyIssue<T>
where ReportHierarchyIssue<T>: Send + Sync + 'static,

Implementors§

Source§

impl Resource for UpdateStatus
where Self: Send + Sync + 'static,

Source§

impl Resource for ReportExecutionOrderAmbiguities

Source§

impl Resource for AppTypeRegistry
where AppTypeRegistry: Send + Sync + 'static,

Source§

impl Resource for Gamepads
where Gamepads: Send + Sync + 'static,

Source§

impl Resource for TaskPoolOptions
where TaskPoolOptions: Send + Sync + 'static,

Source§

impl Resource for Time
where Time: Send + Sync + 'static,

Source§

impl Resource for Touches
where Touches: Send + Sync + 'static,

Source§

impl Resource for Windows
where Windows: Send + Sync + 'static,

Source§

impl<E> Resource for Events<E>
where E: Event, Events<E>: Send + Sync + 'static,

Source§

impl<T> Resource for Axis<T>
where Axis<T>: Send + Sync + 'static,

Source§

impl<T> Resource for Input<T>
where T: Copy + Eq + Hash + Send + Sync + 'static, Input<T>: Send + Sync + 'static,

Source§

impl<T> Resource for State<T>
where T: StateData, State<T>: Send + Sync + 'static,