Skip to main content

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);
}

§!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.


#[derive(Resource)]
struct NotSync {
   counter: RefCell<usize>,
}

This will compile since the RefCell is wrapped with SyncCell.

use bevy_platform::cell::SyncCell;

#[derive(Resource)]
struct ActuallySync {
   counter: SyncCell<RefCell<usize>>,
}

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for BuildIndirectParametersBindGroups

Source§

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

Source§

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

Source§

impl Resource for CompressedImageFormatSupport

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for DefaultOpaqueRendererMethod

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for EnvironmentMapUniformBuffer

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for FallbackImageFormatMsaaCache

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for GlobalClusterableObjectMeta

Source§

impl Resource for GlobalVisibleClusterableObjects

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for ManageAccessibilityUpdates

Source§

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

Source§

impl Resource for MaterialBindGroupAllocators

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for MeshesToReextractNextFrame

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for RenderAssetBytesPerFrameLimiter

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for RenderMeshInstanceGpuQueues

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for ScreenSpaceReflectionsBuffer

Source§

impl Resource for ScreenSpaceReflectionsPipeline

Source§

impl Resource for ScreenSpaceTransmissionQuality

Source§

impl Resource for ScreenshotToScreenPipeline

Source§

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

Source§

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

Source§

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

Source§

impl Resource for SpecializedMaterialPipelineCache

Source§

impl Resource for SpecializedPrepassMaterialPipelineCache

Source§

impl Resource for SpecializedShadowMaterialPipelineCache

Source§

impl Resource for SpecializedWireframePipelineCache

Source§

impl Resource for SpecializedWireframePipelineCache

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for StaticTransformOptimizations

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for TilemapChunkMeshCache
where TilemapChunkMeshCache: 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 Resource for TimeUpdateStrategy
where TimeUpdateStrategy: Send + Sync + 'static,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for ViewPrepassSpecializationTicks

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for WinitActionRequestHandlers

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl Resource for WireframeEntitiesNeedingSpecialization

Source§

impl Resource for WireframeEntitiesNeedingSpecialization

Source§

impl Resource for WireframeEntitySpecializationTicks

Source§

impl Resource for WireframeEntitySpecializationTicks

Source§

impl<A> Resource for Assets<A>
where A: Asset, Assets<A>: Send + Sync + 'static,

Source§

impl<A> Resource for ExtractedAssets<A>
where A: ErasedRenderAsset, ExtractedAssets<A>: Send + Sync + 'static,

Source§

impl<A> Resource for ExtractedAssets<A>
where A: RenderAsset, ExtractedAssets<A>: Send + Sync + 'static,

Source§

impl<A> Resource for PrepareNextFrameAssets<A>

Source§

impl<A> Resource for PrepareNextFrameAssets<A>
where A: RenderAsset, PrepareNextFrameAssets<A>: Send + Sync + 'static,

Source§

impl<A> Resource for RenderAssets<A>
where A: RenderAsset, RenderAssets<A>: Send + Sync + 'static,

Source§

impl<BD, BDI> Resource for BatchedInstanceBuffers<BD, BDI>
where BD: GpuArrayBufferable + Sync + Send + 'static, BDI: Pod + Default, BatchedInstanceBuffers<BD, BDI>: Send + Sync + 'static,

Source§

impl<BD> Resource for BatchedInstanceBuffer<BD>
where BD: GpuArrayBufferable + Sync + Send + 'static, BatchedInstanceBuffer<BD>: Send + Sync + 'static,

Source§

impl<BPI> Resource for ViewBinnedRenderPhases<BPI>
where BPI: BinnedPhaseItem, ViewBinnedRenderPhases<BPI>: Send + Sync + 'static,

Source§

impl<C> Resource for ComponentUniforms<C>
where C: Component + ShaderType, ComponentUniforms<C>: Send + Sync + 'static,

Source§

impl<EI> Resource for ExtractedInstances<EI>
where EI: ExtractInstance, ExtractedInstances<EI>: Send + Sync + 'static,

Source§

impl<ERA> Resource for ErasedRenderAssets<ERA>
where ErasedRenderAssets<ERA>: Send + Sync + 'static,

Source§

impl<M> Resource for EntitiesNeedingSpecialization<M>
where EntitiesNeedingSpecialization<M>: Send + Sync + 'static,

Source§

impl<M> Resource for EntitiesNeedingSpecialization<M>
where EntitiesNeedingSpecialization<M>: Send + Sync + 'static,

Source§

impl<M> Resource for EntitySpecializationTickPair<M>
where EntitySpecializationTickPair<M>: Send + Sync + 'static,

Source§

impl<M> Resource for Material2dPipeline<M>
where M: Material2d, Material2dPipeline<M>: Send + Sync + 'static,

Source§

impl<M> Resource for RenderMaterial2dInstances<M>
where M: Material2d, RenderMaterial2dInstances<M>: Send + Sync + 'static,

Source§

impl<M> Resource for SpecializedMaterial2dPipelineCache<M>

Source§

impl<P> Resource for DrawFunctions<P>
where P: PhaseItem, DrawFunctions<P>: Send + Sync + 'static,

Source§

impl<PI, BD> Resource for PhaseBatchedInstanceBuffers<PI, BD>
where PI: PhaseItem, BD: GpuArrayBufferable + Sync + Send + 'static, PhaseBatchedInstanceBuffers<PI, BD>: Send + Sync + 'static,

Source§

impl<PI> Resource for PhaseIndirectParametersBuffers<PI>
where PI: PhaseItem, PhaseIndirectParametersBuffers<PI>: Send + Sync + 'static,

Source§

impl<S> Resource for SpecializedComputePipelines<S>

Source§

impl<S> Resource for SpecializedMeshPipelines<S>

Source§

impl<S> Resource for SpecializedRenderPipelines<S>

Source§

impl<SPI> Resource for ViewSortedRenderPhases<SPI>
where SPI: SortedPhaseItem, ViewSortedRenderPhases<SPI>: Send + Sync + 'static,

Source§

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

Source§

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

Source§

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

Implementors§

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<E> Resource for Messages<E>
where E: Message, Messages<E>: Send + Sync + 'static,

Source§

impl<S> Resource for CachedSystemId<S>
where CachedSystemId<S>: Send + Sync + 'static,

Source§

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