pub struct WorldAccessGuard<'w> { /* private fields */ }Expand description
Provides safe access to the world via [WorldAccess] permissions, which enforce aliasing rules at runtime in multi-thread environments
Implementations§
Source§impl WorldAccessGuard<'_>
impl WorldAccessGuard<'_>
Sourcepub fn query(
&self,
query: ScriptQueryBuilder,
) -> Result<VecDeque<ScriptQueryResult>, InteropError>
pub fn query( &self, query: ScriptQueryBuilder, ) -> Result<VecDeque<ScriptQueryResult>, InteropError>
Queries the world for entities that match the given query.
Source§impl WorldAccessGuard<'_>
Impls to do with dynamically querying systems and schedules
impl WorldAccessGuard<'_>
Impls to do with dynamically querying systems and schedules
Sourcepub fn scope_schedule<O, F: FnOnce(&mut World, &mut Schedule) -> O>(
&self,
label: &ReflectSchedule,
f: F,
) -> Result<O, InteropError>
pub fn scope_schedule<O, F: FnOnce(&mut World, &mut Schedule) -> O>( &self, label: &ReflectSchedule, f: F, ) -> Result<O, InteropError>
Temporarilly removes the given schedule from the world, and calls the given function on it, then re-inserts it.
Useful for initializing schedules, or modifying systems
Sourcepub fn systems(
&self,
schedule: &ReflectSchedule,
) -> Result<Vec<ReflectSystem>, InteropError>
pub fn systems( &self, schedule: &ReflectSchedule, ) -> Result<Vec<ReflectSystem>, InteropError>
Retrieves all the systems in a schedule
Source§impl WorldAccessGuard<'_>
impl WorldAccessGuard<'_>
Sourcepub fn register_script_component(
&self,
component_name: String,
) -> Result<ScriptComponentRegistration, InteropError>
pub fn register_script_component( &self, component_name: String, ) -> Result<ScriptComponentRegistration, InteropError>
Registers a dynamic script component, and returns a reference to its registration
Source§impl WorldAccessGuard<'_>
impl WorldAccessGuard<'_>
Source§impl<'w> WorldAccessGuard<'w>
impl<'w> WorldAccessGuard<'w>
Sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Invalidates the world access guard, making it and any guards derived from this one unusable.
Sourcepub fn with_static_guard<O>(
world: &'w mut World,
f: impl FnOnce(WorldGuard<'static>) -> O,
) -> O
pub fn with_static_guard<O>( world: &'w mut World, f: impl FnOnce(WorldGuard<'static>) -> O, ) -> O
Safely allows access to the world for the duration of the closure via a static WorldAccessGuard.
The guard is invalidated at the end of the closure, meaning the world cannot be accessed at all after the closure ends.
Sourcepub fn with_existing_static_guard<O>(
guard: WorldAccessGuard<'w>,
f: impl FnOnce(WorldGuard<'static>) -> O,
) -> O
pub fn with_existing_static_guard<O>( guard: WorldAccessGuard<'w>, f: impl FnOnce(WorldGuard<'static>) -> O, ) -> O
Safely allows access to the world for the duration of the closure via a static WorldAccessGuard using a previously lifetimed world guard.
Will invalidate the static guard at the end but not the original.
Sourcepub unsafe fn new_non_exclusive(
world: UnsafeWorldCell<'w>,
subset: impl IntoIterator<Item = ReflectAccessId>,
type_registry: AppTypeRegistry,
allocator: AppReflectAllocator,
function_registry: AppScriptFunctionRegistry,
schedule_registry: AppScheduleRegistry,
script_component_registry: AppScriptComponentRegistry,
) -> Self
pub unsafe fn new_non_exclusive( world: UnsafeWorldCell<'w>, subset: impl IntoIterator<Item = ReflectAccessId>, type_registry: AppTypeRegistry, allocator: AppReflectAllocator, function_registry: AppScriptFunctionRegistry, schedule_registry: AppScheduleRegistry, script_component_registry: AppScriptComponentRegistry, ) -> Self
Creates a new WorldAccessGuard from a possibly non-exclusive access to the world.
It requires specyfing the exact accesses that are allowed to be given out by the guard. Those accesses need to be safe to be given out to the script, as the guard will assume that it is safe to give them out in any way.
§Safety
- The caller must ensure that the accesses in subset are not aliased by any other access
- If an access is allowed in this subset, but alised by someone else, either by being converted to mutable or non mutable reference, this guard will be unsafe.
Sourcepub fn new_exclusive(world: &'w mut World) -> Self
pub fn new_exclusive(world: &'w mut World) -> Self
Creates a new WorldAccessGuard for the given mutable borrow of the world.
Creating a guard requires that some resources exist in the world, namely:
If these resources do not exist, they will be initialized.
Sourcepub fn list_accesses(&self) -> Vec<(ReflectAccessId, AccessCount)>
pub fn list_accesses(&self) -> Vec<(ReflectAccessId, AccessCount)>
Purely debugging utility to list all accesses currently held.
Sourcepub unsafe fn release_all_accesses(&self)
pub unsafe fn release_all_accesses(&self)
Should only really be used for testing purposes
Sourcepub fn access_len(&self) -> usize
pub fn access_len(&self) -> usize
Returns the number of accesses currently held.
Sourcepub fn as_unsafe_world_cell(&self) -> Result<UnsafeWorldCell<'w>, InteropError>
pub fn as_unsafe_world_cell(&self) -> Result<UnsafeWorldCell<'w>, InteropError>
Retrieves the underlying unsafe world cell, with no additional guarantees of safety proceed with caution and only use this if you understand what you’re doing
Sourcepub fn as_unsafe_world_cell_readonly(
&self,
) -> Result<UnsafeWorldCell<'w>, InteropError>
pub fn as_unsafe_world_cell_readonly( &self, ) -> Result<UnsafeWorldCell<'w>, InteropError>
Retrieves the underlying read only unsafe world cell, with no additional guarantees of safety proceed with caution and only use this if you understand what you’re doing
Sourcepub fn get_component_id(
&self,
id: TypeId,
) -> Result<Option<ComponentId>, InteropError>
pub fn get_component_id( &self, id: TypeId, ) -> Result<Option<ComponentId>, InteropError>
Gets the component id of the given component or resource
Sourcepub fn get_resource_id(
&self,
id: TypeId,
) -> Result<Option<ComponentId>, InteropError>
pub fn get_resource_id( &self, id: TypeId, ) -> Result<Option<ComponentId>, InteropError>
Gets the resource id of the given component or resource
Sourcepub fn with_read_access<T: Into<ReflectAccessId>, O, F: FnOnce(&Self) -> O>(
&self,
id: T,
closure: F,
) -> Result<O, ()>
pub fn with_read_access<T: Into<ReflectAccessId>, O, F: FnOnce(&Self) -> O>( &self, id: T, closure: F, ) -> Result<O, ()>
A utility for running a closure with scoped read access to the given id
Sourcepub fn with_write_access<T: Into<ReflectAccessId>, O, F: FnOnce(&Self) -> O>(
&self,
id: T,
closure: F,
) -> Result<O, ()>
pub fn with_write_access<T: Into<ReflectAccessId>, O, F: FnOnce(&Self) -> O>( &self, id: T, closure: F, ) -> Result<O, ()>
A utility for running a closure with scoped write access to the given id
Sourcepub fn get_access_location(
&self,
raid: ReflectAccessId,
) -> Option<Location<'static>>
pub fn get_access_location( &self, raid: ReflectAccessId, ) -> Option<Location<'static>>
Get the location of the given access
Sourcepub fn claim_read_access(&self, raid: ReflectAccessId) -> bool
pub fn claim_read_access(&self, raid: ReflectAccessId) -> bool
Claims read access to the given type.
Sourcepub fn claim_write_access(&self, raid: ReflectAccessId) -> bool
pub fn claim_write_access(&self, raid: ReflectAccessId) -> bool
Claims write access to the given type.
Sourcepub unsafe fn release_access(&self, raid: ReflectAccessId)
pub unsafe fn release_access(&self, raid: ReflectAccessId)
Releases read or write access to the given type.
§Safety
- This can only be called safely after all references to the type created using the access have been dropped
- You can only call this if you previously called one of:
WorldAccessGuard::claim_read_accessorWorldAccessGuard::claim_write_access - The number of claim and release calls for the same id must always match
Sourcepub fn claim_global_access(&self) -> bool
pub fn claim_global_access(&self) -> bool
Claims global access to the world
Sourcepub unsafe fn release_global_access(&self)
pub unsafe fn release_global_access(&self)
Releases global access to the world
§Safety
- This can only be called safely after all references created using the access have been dropped
Sourcepub fn type_registry(&self) -> TypeRegistryArc
pub fn type_registry(&self) -> TypeRegistryArc
Returns the type registry for the world
Sourcepub fn schedule_registry(&self) -> AppScheduleRegistry
pub fn schedule_registry(&self) -> AppScheduleRegistry
Returns the schedule registry for the world
Sourcepub fn component_registry(&self) -> AppScriptComponentRegistry
pub fn component_registry(&self) -> AppScriptComponentRegistry
Returns the component registry for the world
Sourcepub fn allocator(&self) -> AppReflectAllocator
pub fn allocator(&self) -> AppReflectAllocator
Returns the script allocator for the world
Sourcepub fn script_function_registry(&self) -> AppScriptFunctionRegistry
pub fn script_function_registry(&self) -> AppScriptFunctionRegistry
Returns the function registry for the world
Sourcepub fn with_global_access<F: FnOnce(&mut World) -> O, O>(
&self,
f: F,
) -> Result<O, InteropError>
pub fn with_global_access<F: FnOnce(&mut World) -> O, O>( &self, f: F, ) -> Result<O, InteropError>
Claims access to the world for the duration of the closure, allowing for global access to the world.
Sourcepub fn with_resource<F, R, O>(&self, f: F) -> Result<O, InteropError>
pub fn with_resource<F, R, O>(&self, f: F) -> Result<O, InteropError>
Safely accesses the resource by claiming and releasing access to it.
§Panics
- if the resource does not exist
Sourcepub fn with_resource_mut<F, R, O>(&self, f: F) -> Result<O, InteropError>
pub fn with_resource_mut<F, R, O>(&self, f: F) -> Result<O, InteropError>
Safely accesses the resource by claiming and releasing access to it.
§Panics
- if the resource does not exist
Sourcepub fn with_component<F, T, O>(
&self,
entity: Entity,
f: F,
) -> Result<O, InteropError>
pub fn with_component<F, T, O>( &self, entity: Entity, f: F, ) -> Result<O, InteropError>
Safely accesses the component by claiming and releasing access to it.
Sourcepub fn with_component_mut<F, T, O>(
&self,
entity: Entity,
f: F,
) -> Result<O, InteropError>
pub fn with_component_mut<F, T, O>( &self, entity: Entity, f: F, ) -> Result<O, InteropError>
Safely accesses the component by claiming and releasing access to it.
Sourcepub fn with_or_insert_component_mut<F, T, O>(
&self,
entity: Entity,
f: F,
) -> Result<O, InteropError>
pub fn with_or_insert_component_mut<F, T, O>( &self, entity: Entity, f: F, ) -> Result<O, InteropError>
Safey modify or insert a component by claiming and releasing global access.
Sourcepub fn lookup_function(
&self,
type_ids: impl IntoIterator<Item = TypeId>,
name: impl Into<Cow<'static, str>>,
) -> Result<DynamicScriptFunction, Cow<'static, str>>
pub fn lookup_function( &self, type_ids: impl IntoIterator<Item = TypeId>, name: impl Into<Cow<'static, str>>, ) -> Result<DynamicScriptFunction, Cow<'static, str>>
Try to lookup a function with the given name on the given type id’s namespaces.
Returns the function if found, otherwise returns the name of the function that was not found.
Sourcepub fn get_functions_on_type(
&self,
type_id: TypeId,
) -> Vec<(Cow<'static, str>, DynamicScriptFunction)>
pub fn get_functions_on_type( &self, type_id: TypeId, ) -> Vec<(Cow<'static, str>, DynamicScriptFunction)>
Iterates over all available functions on the type id’s namespace + those available on any reference if any exist.
Sourcepub fn is_valid_entity(&self, entity: Entity) -> Result<bool, InteropError>
pub fn is_valid_entity(&self, entity: Entity) -> Result<bool, InteropError>
checks if a given entity exists and is valid
Sourcepub fn try_call_overloads(
&self,
type_id: TypeId,
name: impl Into<Cow<'static, str>>,
args: Vec<ScriptValue>,
context: FunctionCallContext,
) -> Result<ScriptValue, InteropError>
pub fn try_call_overloads( &self, type_id: TypeId, name: impl Into<Cow<'static, str>>, args: Vec<ScriptValue>, context: FunctionCallContext, ) -> Result<ScriptValue, InteropError>
Tries to call a fitting overload of the function with the given name and in the type id’s namespace based on the arguments provided. Currently does this by repeatedly trying each overload until one succeeds or all fail.
Source§impl WorldAccessGuard<'_>
Impl block for higher level world methods
impl WorldAccessGuard<'_>
Impl block for higher level world methods
Sourcepub fn construct(
&self,
type_: ScriptTypeRegistration,
payload: HashMap<String, ScriptValue>,
one_indexed: bool,
) -> Result<Box<dyn PartialReflect>, InteropError>
pub fn construct( &self, type_: ScriptTypeRegistration, payload: HashMap<String, ScriptValue>, one_indexed: bool, ) -> Result<Box<dyn PartialReflect>, InteropError>
An arbitrary type constructor utility.
Allows the construction of arbitrary types (within limits dictated by the API) from the script directly
Sourcepub fn load_script_asset(
&self,
asset_path: &str,
) -> Result<Handle<ScriptAsset>, InteropError>
pub fn load_script_asset( &self, asset_path: &str, ) -> Result<Handle<ScriptAsset>, InteropError>
Loads a script from the given asset path with default settings.
Sourcepub fn get_script_asset_load_state(
&self,
script: Handle<ScriptAsset>,
) -> Result<LoadState, InteropError>
pub fn get_script_asset_load_state( &self, script: Handle<ScriptAsset>, ) -> Result<LoadState, InteropError>
Checks the load state of a script asset.
Sourcepub fn spawn(&self) -> Result<Entity, InteropError>
pub fn spawn(&self) -> Result<Entity, InteropError>
Spawns a new entity in the world
Sourcepub fn get_type_by_name(
&self,
type_name: &str,
) -> Option<ScriptTypeRegistration>
pub fn get_type_by_name( &self, type_name: &str, ) -> Option<ScriptTypeRegistration>
get a type registration for the type, without checking if it’s a component or resource
Sourcepub fn get_type_registration_by_name(
&self,
type_name: String,
) -> Result<Option<Union<ScriptTypeRegistration, Union<ScriptComponentRegistration, ScriptResourceRegistration>>>, InteropError>
pub fn get_type_registration_by_name( &self, type_name: String, ) -> Result<Option<Union<ScriptTypeRegistration, Union<ScriptComponentRegistration, ScriptResourceRegistration>>>, InteropError>
Similar to Self::get_type_by_name but returns a type erased ScriptTypeRegistration, ScriptComponentRegistration or ScriptResourceRegistration
depending on the underlying type and state of the world.
Sourcepub fn get_schedule_by_name(
&self,
schedule_name: String,
) -> Option<ReflectSchedule>
pub fn get_schedule_by_name( &self, schedule_name: String, ) -> Option<ReflectSchedule>
get a schedule by name
Sourcepub fn get_component_type(
&self,
registration: ScriptTypeRegistration,
) -> Result<Result<ScriptComponentRegistration, ScriptTypeRegistration>, InteropError>
pub fn get_component_type( &self, registration: ScriptTypeRegistration, ) -> Result<Result<ScriptComponentRegistration, ScriptTypeRegistration>, InteropError>
get a component type registration for the type
Sourcepub fn get_resource_type(
&self,
registration: ScriptTypeRegistration,
) -> Result<Result<ScriptResourceRegistration, ScriptTypeRegistration>, InteropError>
pub fn get_resource_type( &self, registration: ScriptTypeRegistration, ) -> Result<Result<ScriptResourceRegistration, ScriptTypeRegistration>, InteropError>
get a resource type registration for the type
Sourcepub fn add_default_component(
&self,
entity: Entity,
registration: ScriptComponentRegistration,
) -> Result<(), InteropError>
pub fn add_default_component( &self, entity: Entity, registration: ScriptComponentRegistration, ) -> Result<(), InteropError>
add a default component to an entity
Sourcepub fn insert_component(
&self,
entity: Entity,
registration: ScriptComponentRegistration,
value: ReflectReference,
) -> Result<(), InteropError>
pub fn insert_component( &self, entity: Entity, registration: ScriptComponentRegistration, value: ReflectReference, ) -> Result<(), InteropError>
insert the component into the entity
Sourcepub fn get_component(
&self,
entity: Entity,
component_registration: ScriptComponentRegistration,
) -> Result<Option<ReflectReference>, InteropError>
pub fn get_component( &self, entity: Entity, component_registration: ScriptComponentRegistration, ) -> Result<Option<ReflectReference>, InteropError>
get the component from the entity
Sourcepub fn has_component(
&self,
entity: Entity,
component_id: ComponentId,
) -> Result<bool, InteropError>
pub fn has_component( &self, entity: Entity, component_id: ComponentId, ) -> Result<bool, InteropError>
check if the entity has the component
Sourcepub fn remove_component(
&self,
entity: Entity,
registration: ScriptComponentRegistration,
) -> Result<(), InteropError>
pub fn remove_component( &self, entity: Entity, registration: ScriptComponentRegistration, ) -> Result<(), InteropError>
remove the component from the entity
Sourcepub fn get_resource(
&self,
resource_id: ComponentId,
) -> Result<Option<ReflectReference>, InteropError>
pub fn get_resource( &self, resource_id: ComponentId, ) -> Result<Option<ReflectReference>, InteropError>
get the given resource
Sourcepub fn remove_resource(
&self,
registration: ScriptResourceRegistration,
) -> Result<(), InteropError>
pub fn remove_resource( &self, registration: ScriptResourceRegistration, ) -> Result<(), InteropError>
remove the given resource
Sourcepub fn has_resource(
&self,
resource_id: ComponentId,
) -> Result<bool, InteropError>
pub fn has_resource( &self, resource_id: ComponentId, ) -> Result<bool, InteropError>
check if the entity has the resource
Sourcepub fn has_entity(&self, entity: Entity) -> Result<bool, InteropError>
pub fn has_entity(&self, entity: Entity) -> Result<bool, InteropError>
check the given entity exists
Sourcepub fn get_children(&self, entity: Entity) -> Result<Vec<Entity>, InteropError>
pub fn get_children(&self, entity: Entity) -> Result<Vec<Entity>, InteropError>
get the children of the given entity
Sourcepub fn get_parent(&self, entity: Entity) -> Result<Option<Entity>, InteropError>
pub fn get_parent(&self, entity: Entity) -> Result<Option<Entity>, InteropError>
get the parent of the given entity
Sourcepub fn push_children(
&self,
parent: Entity,
children: &[Entity],
) -> Result<(), InteropError>
pub fn push_children( &self, parent: Entity, children: &[Entity], ) -> Result<(), InteropError>
insert children into the given entity
Sourcepub fn remove_children(
&self,
parent: Entity,
children: &[Entity],
) -> Result<(), InteropError>
pub fn remove_children( &self, parent: Entity, children: &[Entity], ) -> Result<(), InteropError>
remove children from the given entity
Sourcepub fn insert_children(
&self,
parent: Entity,
index: usize,
children: &[Entity],
) -> Result<(), InteropError>
pub fn insert_children( &self, parent: Entity, index: usize, children: &[Entity], ) -> Result<(), InteropError>
insert children into the given entity at the given index
Sourcepub fn despawn_recursive(&self, parent: Entity) -> Result<(), InteropError>
pub fn despawn_recursive(&self, parent: Entity) -> Result<(), InteropError>
despawn this and all children of the given entity recursively
Sourcepub fn despawn_descendants(&self, parent: Entity) -> Result<(), InteropError>
pub fn despawn_descendants(&self, parent: Entity) -> Result<(), InteropError>
despawn all children of the given entity recursively
Sourcepub fn exit(&self) -> Result<(), InteropError>
pub fn exit(&self) -> Result<(), InteropError>
Sends AppExit event to the world with success status
Trait Implementations§
Source§impl<'w> Clone for WorldAccessGuard<'w>
impl<'w> Clone for WorldAccessGuard<'w>
Source§fn clone(&self) -> WorldAccessGuard<'w>
fn clone(&self) -> WorldAccessGuard<'w>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<'w> Freeze for WorldAccessGuard<'w>
impl<'w> !RefUnwindSafe for WorldAccessGuard<'w>
impl<'w> !Send for WorldAccessGuard<'w>
impl<'w> !Sync for WorldAccessGuard<'w>
impl<'w> Unpin for WorldAccessGuard<'w>
impl<'w> !UnwindSafe for WorldAccessGuard<'w>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>, which can then be
downcast into Box<dyn 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>, which 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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoNamespace for Twhere
T: 'static + ?Sized,
impl<T> IntoNamespace for Twhere
T: 'static + ?Sized,
Source§fn into_namespace() -> Namespace
fn into_namespace() -> Namespace
Namespace