pub struct RestrictedWorldView<'w> { /* private fields */ }
Expand description
A view into the world which may only access certain resources and components. A restricted form of &mut World
.
Can be used to access a value, and give out the remaining “&mut World” somewhere else.
§Example usage
use bevy_ecs::prelude::*;
use std::any::TypeId;
use bevy_inspector_egui::restricted_world_view::RestrictedWorldView;
let mut world = World::new();
let mut world = RestrictedWorldView::new(&mut world);
let (mut materials, world) = world.split_off_resource(TypeId::of::<Assets<StandardMaterial>>());
let materials = materials.get_resource_mut::<Assets<StandardMaterial>>();
pass_somewhere_else(world);
Implementations§
source§impl<'w> RestrictedWorldView<'w>
impl<'w> RestrictedWorldView<'w>
Fundamental methods for working with a RestrictedWorldView
sourcepub fn new(world: &'w mut World) -> RestrictedWorldView<'w>
pub fn new(world: &'w mut World) -> RestrictedWorldView<'w>
Create a new RestrictedWorldView
with permission to access everything.
sourcepub fn resources_components(
world: &'w mut World
) -> (RestrictedWorldView<'w>, RestrictedWorldView<'w>)
pub fn resources_components( world: &'w mut World ) -> (RestrictedWorldView<'w>, RestrictedWorldView<'w>)
Splits the world into one view which may only be used for resource access, and another which may only be used for component access.
pub fn world(&self) -> UnsafeWorldCell<'w>
sourcepub fn allows_access_to_resource(&self, type_id: TypeId) -> bool
pub fn allows_access_to_resource(&self, type_id: TypeId) -> bool
Whether the resource with the given TypeId
may be accessed from this world view
sourcepub fn allows_access_to_component(&self, component: (Entity, TypeId)) -> bool
pub fn allows_access_to_component(&self, component: (Entity, TypeId)) -> bool
Whether the given component at the entity may be accessed from this world view
sourcepub fn split_off_resource(
&mut self,
resource: TypeId
) -> (RestrictedWorldView<'_>, RestrictedWorldView<'_>)
pub fn split_off_resource( &mut self, resource: TypeId ) -> (RestrictedWorldView<'_>, RestrictedWorldView<'_>)
Splits this view into one view that only has access the the resource resource
(.0
), and the rest (.1
).
sourcepub fn split_off_resource_typed<R: Resource>(
self
) -> Option<(Mut<'w, R>, RestrictedWorldView<'w>)>
pub fn split_off_resource_typed<R: Resource>( self ) -> Option<(Mut<'w, R>, RestrictedWorldView<'w>)>
Like RestrictedWorldView::split_off_resource
, but takes self
and returns 'w
lifetimes.
sourcepub fn split_off_component(
&mut self,
component: (Entity, TypeId)
) -> (RestrictedWorldView<'_>, RestrictedWorldView<'_>)
pub fn split_off_component( &mut self, component: (Entity, TypeId) ) -> (RestrictedWorldView<'_>, RestrictedWorldView<'_>)
Splits this view into one view that only has access the the component component.1
at the entity component.0
(.0
), and the rest (.1
).
sourcepub fn split_off_components(
&mut self,
components: impl Iterator<Item = (Entity, TypeId)> + Copy
) -> (RestrictedWorldView<'_>, RestrictedWorldView<'_>)
pub fn split_off_components( &mut self, components: impl Iterator<Item = (Entity, TypeId)> + Copy ) -> (RestrictedWorldView<'_>, RestrictedWorldView<'_>)
Splits this view into one view that only has access the the component-entity pairs components
(.0
), and the rest (.1
)
source§impl<'w> RestrictedWorldView<'w>
impl<'w> RestrictedWorldView<'w>
Some safe methods for getting values out of the RestrictedWorldView
.
Also has some methods for getting values in their Reflect
form.
pub fn contains_entity(&self, entity: Entity) -> bool
sourcepub fn get_resource_mut<R: Resource>(&mut self) -> Result<Mut<'_, R>, Error>
pub fn get_resource_mut<R: Resource>(&mut self) -> Result<Mut<'_, R>, Error>
Gets a mutable reference to the resource of the given type
sourcepub fn get_two_resources_mut<R1: Resource, R2: Resource>(
&mut self
) -> (Result<Mut<'_, R1>, Error>, Result<Mut<'_, R2>, Error>)
pub fn get_two_resources_mut<R1: Resource, R2: Resource>( &mut self ) -> (Result<Mut<'_, R1>, Error>, Result<Mut<'_, R2>, Error>)
Gets mutable reference to two resources. Panics if R1 = R2
.
sourcepub fn get_resource_reflect_mut_by_id(
&mut self,
type_id: TypeId,
type_registry: &TypeRegistry
) -> Result<(&mut dyn Reflect, impl FnOnce() + '_), Error>
pub fn get_resource_reflect_mut_by_id( &mut self, type_id: TypeId, type_registry: &TypeRegistry ) -> Result<(&mut dyn Reflect, impl FnOnce() + '_), Error>
Gets a mutable reference in form of a &mut dyn Reflect
to the resource given by type_id
.
Returns an error if the type does not register Reflect
.
Also returns a impl FnOnce()
to mark the value as changed.
sourcepub fn get_entity_component_reflect(
&mut self,
entity: Entity,
component: TypeId,
type_registry: &TypeRegistry
) -> Result<(&mut dyn Reflect, bool, impl FnOnce() + '_), Error>
pub fn get_entity_component_reflect( &mut self, entity: Entity, component: TypeId, type_registry: &TypeRegistry ) -> Result<(&mut dyn Reflect, bool, impl FnOnce() + '_), Error>
Gets a mutable reference in form of a &mut dyn Reflect
to a component at an entity.
Returns an error if the type does not register Reflect
.
Also returns a impl FnOnce()
to mark the value as changed.
Trait Implementations§
Auto Trait Implementations§
impl<'w> Freeze for RestrictedWorldView<'w>
impl<'w> !RefUnwindSafe for RestrictedWorldView<'w>
impl<'w> Send for RestrictedWorldView<'w>
impl<'w> Sync for RestrictedWorldView<'w>
impl<'w> Unpin for RestrictedWorldView<'w>
impl<'w> !UnwindSafe for RestrictedWorldView<'w>
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.