Struct FilteredResources
pub struct FilteredResources<'w, 's> { /* private fields */ }Expand description
Provides read-only access to a set of Resources defined by the contained [Access].
Use FilteredResourcesMut if you need mutable access to some resources.
To be useful as a SystemParam,
this must be configured using a FilteredResourcesParamBuilder
to build the system using a SystemParamBuilder.
§Examples
// Use `FilteredResourcesParamBuilder` to declare access to resources.
let system = (FilteredResourcesParamBuilder::new(|builder| {
builder.add_read::<B>().add_read::<C>();
}),)
.build_state(&mut world)
.build_system(resource_system);
world.init_resource::<A>();
world.init_resource::<C>();
fn resource_system(res: FilteredResources) {
// The resource exists, but we have no access, so we can't read it.
assert!(res.get::<A>().is_err());
// The resource doesn't exist, so we can't read it.
assert!(res.get::<B>().is_err());
// The resource exists and we have access, so we can read it.
let c = res.get::<C>().unwrap();
// The type parameter can be left out if it can be determined from use.
let c: Ref<C> = res.get().unwrap();
}This can be used alongside ordinary Res and ResMut parameters if they do not conflict.
let system = (
FilteredResourcesParamBuilder::new(|builder| {
builder.add_read::<A>();
}),
ParamBuilder,
ParamBuilder,
)
.build_state(&mut world)
.build_system(resource_system);
// Read access to A does not conflict with read access to A or write access to B.
fn resource_system(filtered: FilteredResources, res_a: Res<A>, res_mut_b: ResMut<B>) {
let res_a_2: Ref<A> = filtered.get::<A>().unwrap();
}But it will conflict if it tries to read the same resource that another parameter writes.
ⓘ
let system = (
FilteredResourcesParamBuilder::new(|builder| {
builder.add_read::<A>();
}),
ParamBuilder,
)
.build_state(&mut world)
.build_system(invalid_resource_system);
// Read access to A conflicts with write access to A.
fn invalid_resource_system(filtered: FilteredResources, res_mut_a: ResMut<A>) { }Implementations§
§impl<'w, 's> FilteredResources<'w, 's>
impl<'w, 's> FilteredResources<'w, 's>
pub fn access(&self) -> &Access
pub fn access(&self) -> &Access
Returns a reference to the underlying [Access].
pub fn has_read<R>(&self) -> boolwhere
R: Resource,
pub fn has_read<R>(&self) -> boolwhere
R: Resource,
Returns true if the FilteredResources has access to the given resource.
Note that Self::get() may still return Err if the resource does not exist.
Trait Implementations§
§impl<'w, 's> Clone for FilteredResources<'w, 's>
impl<'w, 's> Clone for FilteredResources<'w, 's>
§fn clone(&self) -> FilteredResources<'w, 's>
fn clone(&self) -> FilteredResources<'w, 's>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read more§impl<'w, 's> From<&'w FilteredResourcesMut<'_, 's>> for FilteredResources<'w, 's>
impl<'w, 's> From<&'w FilteredResourcesMut<'_, 's>> for FilteredResources<'w, 's>
§fn from(
resources: &'w FilteredResourcesMut<'_, 's>,
) -> FilteredResources<'w, 's>
fn from( resources: &'w FilteredResourcesMut<'_, 's>, ) -> FilteredResources<'w, 's>
Converts to this type from the input type.
§impl<'w> From<&'w World> for FilteredResources<'w, 'static>
impl<'w> From<&'w World> for FilteredResources<'w, 'static>
§fn from(value: &'w World) -> FilteredResources<'w, 'static>
fn from(value: &'w World) -> FilteredResources<'w, 'static>
Converts to this type from the input type.
§impl<'w> From<&'w mut World> for FilteredResources<'w, 'static>
impl<'w> From<&'w mut World> for FilteredResources<'w, 'static>
§fn from(value: &'w mut World) -> FilteredResources<'w, 'static>
fn from(value: &'w mut World) -> FilteredResources<'w, 'static>
Converts to this type from the input type.
§impl<'w, 's> From<FilteredResourcesMut<'w, 's>> for FilteredResources<'w, 's>
impl<'w, 's> From<FilteredResourcesMut<'w, 's>> for FilteredResources<'w, 's>
§fn from(resources: FilteredResourcesMut<'w, 's>) -> FilteredResources<'w, 's>
fn from(resources: FilteredResourcesMut<'w, 's>) -> FilteredResources<'w, 's>
Converts to this type from the input type.
§impl SystemParam for FilteredResources<'_, '_>
impl SystemParam for FilteredResources<'_, '_>
§type Item<'world, 'state> = FilteredResources<'world, 'state>
type Item<'world, 'state> = FilteredResources<'world, 'state>
The item type returned when constructing this system param.
The value of this associated type should be
Self, instantiated with new lifetimes. Read more§fn init_state(
_world: &mut World,
) -> <FilteredResources<'_, '_> as SystemParam>::State
fn init_state( _world: &mut World, ) -> <FilteredResources<'_, '_> as SystemParam>::State
Creates a new instance of this param’s
State.§fn init_access(
access: &<FilteredResources<'_, '_> as SystemParam>::State,
system_meta: &mut SystemMeta,
component_access_set: &mut FilteredAccessSet,
world: &mut World,
)
fn init_access( access: &<FilteredResources<'_, '_> as SystemParam>::State, system_meta: &mut SystemMeta, component_access_set: &mut FilteredAccessSet, world: &mut World, )
§unsafe fn get_param<'world, 'state>(
state: &'state mut <FilteredResources<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'world>,
change_tick: Tick,
) -> Result<<FilteredResources<'_, '_> as SystemParam>::Item<'world, 'state>, SystemParamValidationError>
unsafe fn get_param<'world, 'state>( state: &'state mut <FilteredResources<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'world>, change_tick: Tick, ) -> Result<<FilteredResources<'_, '_> as SystemParam>::Item<'world, 'state>, SystemParamValidationError>
Creates a parameter to be passed into a
SystemParamFunction. Read more§fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
Applies any deferred mutations stored in this [
SystemParam]’s state.
This is used to apply Commands during ApplyDeferred.§fn queue(
state: &mut Self::State,
system_meta: &SystemMeta,
world: DeferredWorld<'_>,
)
fn queue( state: &mut Self::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )
Queues any deferred mutations to be applied at the next
ApplyDeferred.§impl<'w, 's, T> SystemParamBuilder<FilteredResources<'w, 's>> for FilteredResourcesParamBuilder<T>where
T: FnOnce(&mut FilteredResourcesBuilder<'_>),
impl<'w, 's, T> SystemParamBuilder<FilteredResources<'w, 's>> for FilteredResourcesParamBuilder<T>where
T: FnOnce(&mut FilteredResourcesBuilder<'_>),
§fn build(
self,
world: &mut World,
) -> <FilteredResources<'w, 's> as SystemParam>::State
fn build( self, world: &mut World, ) -> <FilteredResources<'w, 's> as SystemParam>::State
§fn build_state(self, world: &mut World) -> SystemState<P>
fn build_state(self, world: &mut World) -> SystemState<P>
Create a [
SystemState] from a SystemParamBuilder.
To create a system, call [SystemState::build_system] on the result.§fn build_system<Marker, In, Out, Func>(
self,
func: Func,
) -> IntoBuilderSystem<Marker, In, Out, Func, Self>where
Self: 'static,
Func: SystemParamFunction<Marker, Param = P>,
fn build_system<Marker, In, Out, Func>(
self,
func: Func,
) -> IntoBuilderSystem<Marker, In, Out, Func, Self>where
Self: 'static,
Func: SystemParamFunction<Marker, Param = P>,
impl<'w, 's> Copy for FilteredResources<'w, 's>
impl ReadOnlySystemParam for FilteredResources<'_, '_>
Auto Trait Implementations§
impl<'w, 's> Freeze for FilteredResources<'w, 's>
impl<'w, 's> !RefUnwindSafe for FilteredResources<'w, 's>
impl<'w, 's> Send for FilteredResources<'w, 's>
impl<'w, 's> Sync for FilteredResources<'w, 's>
impl<'w, 's> Unpin for FilteredResources<'w, 's>
impl<'w, 's> UnsafeUnpin for FilteredResources<'w, 's>
impl<'w, 's> !UnwindSafe for FilteredResources<'w, 's>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Converts this type into the system output type.