WorldAccessGuard

Struct WorldAccessGuard 

Source
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<'_>

Source

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

Source

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

Source

pub fn systems( &self, schedule: &ReflectSchedule, ) -> Result<Vec<ReflectSystem>, InteropError>

Retrieves all the systems in a schedule

Source§

impl WorldAccessGuard<'_>

Source

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<'_>

Source

pub fn id(&self) -> WorldId

Returns the id of the world this guard provides access to

Source§

impl<'w> WorldAccessGuard<'w>

Source

pub fn invalidate(&self)

Invalidates the world access guard, making it and any guards derived from this one unusable.

Source

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.

Source

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.

Source

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.
Source

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.

Source

pub fn list_accesses(&self) -> Vec<(ReflectAccessId, AccessCount)>

Purely debugging utility to list all accesses currently held.

Source

pub unsafe fn release_all_accesses(&self)

Should only really be used for testing purposes

Source

pub fn access_len(&self) -> usize

Returns the number of accesses currently held.

Source

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

Source

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

Source

pub fn get_component_id( &self, id: TypeId, ) -> Result<Option<ComponentId>, InteropError>

Gets the component id of the given component or resource

Source

pub fn get_resource_id( &self, id: TypeId, ) -> Result<Option<ComponentId>, InteropError>

Gets the resource id of the given component or resource

Source

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

Source

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

Source

pub fn get_access_location( &self, raid: ReflectAccessId, ) -> Option<Location<'static>>

Get the location of the given access

Source

pub fn claim_read_access(&self, raid: ReflectAccessId) -> bool

Claims read access to the given type.

Source

pub fn claim_write_access(&self, raid: ReflectAccessId) -> bool

Claims write access to the given type.

Source

pub unsafe fn release_access(&self, raid: ReflectAccessId)

Releases read or write access to the given type.

§Safety
Source

pub fn claim_global_access(&self) -> bool

Claims global access to the world

Source

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
Source

pub fn type_registry(&self) -> TypeRegistryArc

Returns the type registry for the world

Source

pub fn schedule_registry(&self) -> AppScheduleRegistry

Returns the schedule registry for the world

Source

pub fn component_registry(&self) -> AppScriptComponentRegistry

Returns the component registry for the world

Source

pub fn allocator(&self) -> AppReflectAllocator

Returns the script allocator for the world

Source

pub fn script_function_registry(&self) -> AppScriptFunctionRegistry

Returns the function registry for the world

Source

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.

Source

pub fn with_resource<F, R, O>(&self, f: F) -> Result<O, InteropError>
where R: Resource, F: FnOnce(&R) -> O,

Safely accesses the resource by claiming and releasing access to it.

§Panics
  • if the resource does not exist
Source

pub fn with_resource_mut<F, R, O>(&self, f: F) -> Result<O, InteropError>
where R: Resource, F: FnOnce(Mut<'_, R>) -> O,

Safely accesses the resource by claiming and releasing access to it.

§Panics
  • if the resource does not exist
Source

pub fn with_component<F, T, O>( &self, entity: Entity, f: F, ) -> Result<O, InteropError>
where T: Component, F: FnOnce(Option<&T>) -> O,

Safely accesses the component by claiming and releasing access to it.

Source

pub fn with_component_mut<F, T, O>( &self, entity: Entity, f: F, ) -> Result<O, InteropError>
where T: Component<Mutability = Mutable>, F: FnOnce(Option<Mut<'_, T>>) -> O,

Safely accesses the component by claiming and releasing access to it.

Source

pub fn with_or_insert_component_mut<F, T, O>( &self, entity: Entity, f: F, ) -> Result<O, InteropError>
where T: Component<Mutability = Mutable> + Default, F: FnOnce(&mut T) -> O,

Safey modify or insert a component by claiming and releasing global access.

Source

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.

Source

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.

Source

pub fn is_valid_entity(&self, entity: Entity) -> Result<bool, InteropError>

checks if a given entity exists and is valid

Source

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

Source

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

Source

pub fn load_script_asset( &self, asset_path: &str, ) -> Result<Handle<ScriptAsset>, InteropError>

Loads a script from the given asset path with default settings.

Source

pub fn get_script_asset_load_state( &self, script: Handle<ScriptAsset>, ) -> Result<LoadState, InteropError>

Checks the load state of a script asset.

Source

pub fn spawn(&self) -> Result<Entity, InteropError>

Spawns a new entity in the world

Source

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

Source

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.

Source

pub fn get_schedule_by_name( &self, schedule_name: String, ) -> Option<ReflectSchedule>

get a schedule by name

Source

pub fn get_component_type( &self, registration: ScriptTypeRegistration, ) -> Result<Result<ScriptComponentRegistration, ScriptTypeRegistration>, InteropError>

get a component type registration for the type

Source

pub fn get_resource_type( &self, registration: ScriptTypeRegistration, ) -> Result<Result<ScriptResourceRegistration, ScriptTypeRegistration>, InteropError>

get a resource type registration for the type

Source

pub fn add_default_component( &self, entity: Entity, registration: ScriptComponentRegistration, ) -> Result<(), InteropError>

add a default component to an entity

Source

pub fn insert_component( &self, entity: Entity, registration: ScriptComponentRegistration, value: ReflectReference, ) -> Result<(), InteropError>

insert the component into the entity

Source

pub fn get_component( &self, entity: Entity, component_registration: ScriptComponentRegistration, ) -> Result<Option<ReflectReference>, InteropError>

get the component from the entity

Source

pub fn has_component( &self, entity: Entity, component_id: ComponentId, ) -> Result<bool, InteropError>

check if the entity has the component

Source

pub fn remove_component( &self, entity: Entity, registration: ScriptComponentRegistration, ) -> Result<(), InteropError>

remove the component from the entity

Source

pub fn get_resource( &self, resource_id: ComponentId, ) -> Result<Option<ReflectReference>, InteropError>

get the given resource

Source

pub fn remove_resource( &self, registration: ScriptResourceRegistration, ) -> Result<(), InteropError>

remove the given resource

Source

pub fn has_resource( &self, resource_id: ComponentId, ) -> Result<bool, InteropError>

check if the entity has the resource

Source

pub fn has_entity(&self, entity: Entity) -> Result<bool, InteropError>

check the given entity exists

Source

pub fn get_children(&self, entity: Entity) -> Result<Vec<Entity>, InteropError>

get the children of the given entity

Source

pub fn get_parent(&self, entity: Entity) -> Result<Option<Entity>, InteropError>

get the parent of the given entity

Source

pub fn push_children( &self, parent: Entity, children: &[Entity], ) -> Result<(), InteropError>

insert children into the given entity

Source

pub fn remove_children( &self, parent: Entity, children: &[Entity], ) -> Result<(), InteropError>

remove children from the given entity

Source

pub fn insert_children( &self, parent: Entity, index: usize, children: &[Entity], ) -> Result<(), InteropError>

insert children into the given entity at the given index

Source

pub fn despawn_recursive(&self, parent: Entity) -> Result<(), InteropError>

despawn this and all children of the given entity recursively

Source

pub fn despawn(&self, entity: Entity) -> Result<(), InteropError>

despawn the given entity

Source

pub fn despawn_descendants(&self, parent: Entity) -> Result<(), InteropError>

despawn all children of the given entity recursively

Source

pub fn exit(&self) -> Result<(), InteropError>

Sends AppExit event to the world with success status

Trait Implementations§

Source§

impl<'w> Clone for WorldAccessGuard<'w>

Source§

fn clone(&self) -> WorldAccessGuard<'w>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'w> Debug for WorldAccessGuard<'w>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoNamespace for T
where T: 'static + ?Sized,

Source§

fn into_namespace() -> Namespace

Converts this type into a Namespace
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more