diff --git a/framework_crates/bones_asset/src/asset.rs b/framework_crates/bones_asset/src/asset.rs index 866a35238b..a27dec4259 100644 --- a/framework_crates/bones_asset/src/asset.rs +++ b/framework_crates/bones_asset/src/asset.rs @@ -217,7 +217,7 @@ pub struct AssetLoc { impl AssetLoc { /// Borrow as an [`AssetLocRef`]. - pub fn as_ref(&self) -> AssetLocRef { + pub fn as_ref(&self) -> AssetLocRef<'_> { AssetLocRef { pack: self.pack.as_deref(), path: &self.path, diff --git a/framework_crates/bones_asset/src/server.rs b/framework_crates/bones_asset/src/server.rs index 1cfd2ce13a..3a78f614f2 100644 --- a/framework_crates/bones_asset/src/server.rs +++ b/framework_crates/bones_asset/src/server.rs @@ -806,7 +806,7 @@ impl AssetServer { } /// Borrow a [`LoadedAsset`] associated to the given handle. - pub fn get_asset_untyped(&self, handle: UntypedHandle) -> Option> { + pub fn get_asset_untyped(&self, handle: UntypedHandle) -> Option> { let cid = self.store.asset_ids.get(&handle)?; self.store.assets.get(&cid) } @@ -815,7 +815,7 @@ impl AssetServer { pub fn get_asset_untyped_mut( &self, handle: UntypedHandle, - ) -> Option> { + ) -> Option> { let cid = self.store.asset_ids.get(&handle)?; self.store.assets.get_mut(&cid) } @@ -826,17 +826,17 @@ impl AssetServer { /// /// Panics if the assets have not be loaded yet with [`AssetServer::load_assets`]. #[track_caller] - pub fn core(&self) -> MappedMutexGuard { + pub fn core(&self) -> MappedMutexGuard<'_, AssetPack> { MutexGuard::map(self.store.core_pack.lock(), |x| x.as_mut().unwrap()) } /// Get the core asset pack's root asset. - pub fn root(&self) -> MappedMapRef { + pub fn root(&self) -> MappedMapRef<'_, Cid, LoadedAsset, T> { self.get(self.core().root.typed()) } /// Get the core asset pack's root asset as a type-erased [`SchemaBox`]. - pub fn untyped_root(&self) -> MappedMapRef { + pub fn untyped_root(&self) -> MappedMapRef<'_, Cid, LoadedAsset, SchemaBox> { self.get_untyped(self.core().root) } @@ -852,7 +852,7 @@ impl AssetServer { /// Panics if the asset is not loaded or if the asset with the given handle doesn't have a /// schema matching `T`. #[track_caller] - pub fn get(&self, handle: Handle) -> MappedMapRef { + pub fn get(&self, handle: Handle) -> MappedMapRef<'_, Cid, LoadedAsset, T> { self.try_get(handle) .expect("asset not found (handle has no cid)") .expect("asset does not have matching schema for given type") @@ -864,7 +864,10 @@ impl AssetServer { /// /// Panics if the asset is not loaded. #[track_caller] - pub fn get_untyped(&self, handle: UntypedHandle) -> MappedMapRef { + pub fn get_untyped( + &self, + handle: UntypedHandle, + ) -> MappedMapRef<'_, Cid, LoadedAsset, SchemaBox> { self.try_get_untyped(handle).unwrap() } @@ -877,7 +880,7 @@ impl AssetServer { pub fn get_untyped_mut( &self, handle: UntypedHandle, - ) -> MappedMapRefMut { + ) -> MappedMapRefMut<'_, Cid, LoadedAsset, SchemaBox> { self.try_get_untyped_mut(handle).unwrap() } @@ -918,7 +921,7 @@ impl AssetServer { pub fn try_get_untyped( &self, handle: UntypedHandle, - ) -> Option> { + ) -> Option> { let cid = self.store.asset_ids.get(&handle)?; Some(MapRef::map(self.store.assets.get(&cid).unwrap(), |x| { &x.data @@ -929,7 +932,7 @@ impl AssetServer { pub fn try_get_untyped_mut( &self, handle: UntypedHandle, - ) -> Option> { + ) -> Option> { let cid = self.store.asset_ids.get_mut(&handle)?; Some(MapRefMut::map( self.store.assets.get_mut(&cid).unwrap(), @@ -968,7 +971,7 @@ impl AssetServer { pub fn get_mut( &mut self, handle: &Handle, - ) -> MappedMapRefMut { + ) -> MappedMapRefMut<'_, Cid, LoadedAsset, T> { let cid = self .store .asset_ids diff --git a/framework_crates/bones_bevy_renderer/src/lib.rs b/framework_crates/bones_bevy_renderer/src/lib.rs index c43d5fa6de..779099c030 100644 --- a/framework_crates/bones_bevy_renderer/src/lib.rs +++ b/framework_crates/bones_bevy_renderer/src/lib.rs @@ -67,7 +67,7 @@ pub struct BonesBevyRenderer { pub struct BonesGame(pub bones::Game); impl BonesGame { /// Shorthand for [`bones::AssetServer`] typed access to the shared resource - pub fn asset_server(&self) -> Option> { + pub fn asset_server(&self) -> Option> { self.0.shared_resource() } } diff --git a/framework_crates/bones_ecs/src/components/typed.rs b/framework_crates/bones_ecs/src/components/typed.rs index bc0bd681bd..4073f6bf72 100644 --- a/framework_crates/bones_ecs/src/components/typed.rs +++ b/framework_crates/bones_ecs/src/components/typed.rs @@ -170,7 +170,7 @@ pub trait ComponentIterBitset<'a, T: HasSchema> { /// Iterates immutably over the components of this type where `bitset` /// indicates the indices of entities. /// Slower than `iter()` but allows joining between multiple component types. - fn iter_with_bitset(&self, bitset: Rc) -> ComponentBitsetIterator; + fn iter_with_bitset(&self, bitset: Rc) -> ComponentBitsetIterator<'_, T>; /// Iterates immutably over the components of this type where `bitset` /// indicates the indices of entities. @@ -178,12 +178,12 @@ pub trait ComponentIterBitset<'a, T: HasSchema> { fn iter_with_bitset_optional( &self, bitset: Rc, - ) -> ComponentBitsetOptionalIterator; + ) -> ComponentBitsetOptionalIterator<'_, T>; /// Iterates mutable over the components of this type where `bitset` /// indicates the indices of entities. /// Slower than `iter()` but allows joining between multiple component types. - fn iter_mut_with_bitset(&mut self, bitset: Rc) -> ComponentBitsetIteratorMut; + fn iter_mut_with_bitset(&mut self, bitset: Rc) -> ComponentBitsetIteratorMut<'_, T>; /// Iterates mutably over the components of this type where `bitset` /// indicates the indices of entities. @@ -191,7 +191,7 @@ pub trait ComponentIterBitset<'a, T: HasSchema> { fn iter_mut_with_bitset_optional( &mut self, bitset: Rc, - ) -> ComponentBitsetOptionalIteratorMut; + ) -> ComponentBitsetOptionalIteratorMut<'_, T>; /// Get bitset of [`ComponentStore`] / implementor. fn bitset(&self) -> &BitSetVec; @@ -207,7 +207,7 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore { /// Gets an immutable reference to the component if there is exactly one instance of it. fn get_single_with_bitset(&self, bitset: Rc) -> Result<&T, QuerySingleError> { // SOUND: we know the schema matches. - fn map(r: SchemaRef) -> &T { + fn map(r: SchemaRef<'_>) -> &T { unsafe { r.cast_into_unchecked() } } self.untyped.get_single_with_bitset(bitset).map(map) @@ -219,7 +219,7 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore { bitset: Rc, ) -> Result<&mut T, QuerySingleError> { // SOUND: we know the schema matches. - fn map(r: SchemaRefMut) -> &mut T { + fn map(r: SchemaRefMut<'_>) -> &mut T { unsafe { r.cast_into_mut_unchecked() } } self.untyped.get_single_with_bitset_mut(bitset).map(map) @@ -229,9 +229,9 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore { /// indicates the indices of entities. /// Slower than `iter()` but allows joining between multiple component types. #[inline] - fn iter_with_bitset(&self, bitset: Rc) -> ComponentBitsetIterator { + fn iter_with_bitset(&self, bitset: Rc) -> ComponentBitsetIterator<'_, T> { // SOUND: we know the schema matches. - fn map(r: SchemaRef) -> &T { + fn map(r: SchemaRef<'_>) -> &T { unsafe { r.cast_into_unchecked() } } self.untyped.iter_with_bitset(bitset).map(map) @@ -244,9 +244,9 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore { fn iter_with_bitset_optional( &self, bitset: Rc, - ) -> ComponentBitsetOptionalIterator { + ) -> ComponentBitsetOptionalIterator<'_, T> { // SOUND: we know the schema matches. - fn map(r: Option) -> Option<&T> { + fn map(r: Option>) -> Option<&T> { r.map(|r| unsafe { r.cast_into_unchecked() }) } self.untyped.iter_with_bitset_optional(bitset).map(map) @@ -256,9 +256,9 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore { /// indicates the indices of entities. /// Slower than `iter()` but allows joining between multiple component types. #[inline] - fn iter_mut_with_bitset(&mut self, bitset: Rc) -> ComponentBitsetIteratorMut { + fn iter_mut_with_bitset(&mut self, bitset: Rc) -> ComponentBitsetIteratorMut<'_, T> { // SOUND: we know the schema matches. - fn map(r: SchemaRefMut) -> &mut T { + fn map(r: SchemaRefMut<'_>) -> &mut T { unsafe { r.cast_into_mut_unchecked() } } @@ -272,9 +272,9 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore { fn iter_mut_with_bitset_optional( &mut self, bitset: Rc, - ) -> ComponentBitsetOptionalIteratorMut { + ) -> ComponentBitsetOptionalIteratorMut<'_, T> { // SOUND: we know the schema matches. - fn map(r: Option) -> Option<&mut T> { + fn map(r: Option>) -> Option<&mut T> { r.map(|r| unsafe { r.cast_into_mut_unchecked() }) } self.untyped.iter_mut_with_bitset_optional(bitset).map(map) diff --git a/framework_crates/bones_ecs/src/components/untyped.rs b/framework_crates/bones_ecs/src/components/untyped.rs index 0ae0a3cdc0..edc80c2938 100644 --- a/framework_crates/bones_ecs/src/components/untyped.rs +++ b/framework_crates/bones_ecs/src/components/untyped.rs @@ -250,12 +250,12 @@ impl UntypedComponentStore { /// Get a [`SchemaRef`] to the component for the given [`Entity`] if the entity has this /// component. #[inline] - pub fn get_ref(&self, entity: Entity) -> Option { + pub fn get_ref(&self, entity: Entity) -> Option> { let idx = entity.index() as usize; self.get_idx(idx) } - fn get_idx(&self, idx: usize) -> Option { + fn get_idx(&self, idx: usize) -> Option> { if self.bitset.bit_test(idx) { // SOUND: we ensure that there is allocated storge for entities that have their bit set. let ptr = unsafe { self.storage.unchecked_idx(idx) }; @@ -377,7 +377,7 @@ impl UntypedComponentStore { pub fn get_many_ref_mut( &mut self, entities: [Entity; N], - ) -> [Option; N] { + ) -> [Option>; N] { // Sort a copy of the passed in entities list. let mut sorted = entities; sorted.sort_unstable(); @@ -494,7 +494,7 @@ impl UntypedComponentStore { pub fn get_single_with_bitset( &self, bitset: Rc, - ) -> Result { + ) -> Result, QuerySingleError> { if self.bitset().bit_count() == 0 || bitset.bit_count() == 0 { // Both bitsets are empty so there are no matches return Err(QuerySingleError::NoEntities); @@ -520,7 +520,7 @@ impl UntypedComponentStore { pub fn get_single_with_bitset_mut( &mut self, bitset: Rc, - ) -> Result { + ) -> Result, QuerySingleError> { if self.bitset().bit_count() == 0 || bitset.bit_count() == 0 { // Both bitsets are empty so there are no matches return Err(QuerySingleError::NoEntities); @@ -565,7 +565,7 @@ impl UntypedComponentStore { /// entities. /// /// Slower than `iter()` but allows joining between multiple component types. - pub fn iter_with_bitset(&self, bitset: Rc) -> UntypedComponentBitsetIterator { + pub fn iter_with_bitset(&self, bitset: Rc) -> UntypedComponentBitsetIterator<'_> { UntypedComponentBitsetIterator { current_id: 0, components: self, @@ -580,7 +580,7 @@ impl UntypedComponentStore { pub fn iter_mut_with_bitset( &mut self, bitset: Rc, - ) -> UntypedComponentBitsetIteratorMut { + ) -> UntypedComponentBitsetIteratorMut<'_> { UntypedComponentBitsetIteratorMut { current_id: 0, components: self, @@ -593,7 +593,7 @@ impl UntypedComponentStore { pub fn iter_with_bitset_optional( &self, bitset: Rc, - ) -> UntypedComponentOptionalBitsetIterator { + ) -> UntypedComponentOptionalBitsetIterator<'_> { let components_count = self.bitset.bit_count(); let query_count = bitset.bit_count(); UntypedComponentOptionalBitsetIterator { @@ -613,7 +613,7 @@ impl UntypedComponentStore { pub fn iter_mut_with_bitset_optional( &mut self, bitset: Rc, - ) -> UntypedComponentOptionalBitsetIteratorMut { + ) -> UntypedComponentOptionalBitsetIteratorMut<'_> { let components_count = self.bitset.bit_count(); let query_count = bitset.bit_count(); UntypedComponentOptionalBitsetIteratorMut { diff --git a/framework_crates/bones_ecs/src/entities.rs b/framework_crates/bones_ecs/src/entities.rs index 50f8f5ecdd..bed900200a 100644 --- a/framework_crates/bones_ecs/src/entities.rs +++ b/framework_crates/bones_ecs/src/entities.rs @@ -610,7 +610,10 @@ impl Entities { /// } /// } /// ``` - pub fn iter_with(&self, query: Q) -> EntitiesIterWith<::Iter> { + pub fn iter_with( + &self, + query: Q, + ) -> EntitiesIterWith<'_, ::Iter> { let mut bitset = self.bitset().clone(); query.apply_bitset(&mut bitset); let bitset = Rc::new(bitset); @@ -722,7 +725,7 @@ impl Entities { } /// Iterates over all alive entities. - pub fn iter(&self) -> EntityIterator { + pub fn iter(&self) -> EntityIterator<'_> { EntityIterator { current_id: 0, next_id: self.next_id, diff --git a/framework_crates/bones_ecs/src/resources.rs b/framework_crates/bones_ecs/src/resources.rs index 372e2ab572..175f9030b0 100644 --- a/framework_crates/bones_ecs/src/resources.rs +++ b/framework_crates/bones_ecs/src/resources.rs @@ -75,13 +75,13 @@ impl UntypedResource { /// Borrow the resource. #[track_caller] - pub fn borrow(&self) -> Ref> { + pub fn borrow(&self) -> Ref<'_, Option> { self.cell.borrow() } /// Mutably borrow the resource. #[track_caller] - pub fn borrow_mut(&self) -> RefMut> { + pub fn borrow_mut(&self) -> RefMut<'_, Option> { self.cell.borrow_mut() } @@ -253,7 +253,7 @@ impl Resources { /// Borrow a resource. #[track_caller] - pub fn get(&self) -> Option> { + pub fn get(&self) -> Option> { let b = self.untyped.get(T::schema()).borrow(); if b.is_some() { Some(Ref::map(b, |b| unsafe { @@ -266,7 +266,7 @@ impl Resources { /// Borrow a resource. #[track_caller] - pub fn get_mut(&self) -> Option> { + pub fn get_mut(&self) -> Option> { let b = self.untyped.get(T::schema()).borrow_mut(); if b.is_some() { Some(RefMut::map(b, |b| unsafe { @@ -373,7 +373,7 @@ impl AtomicResource { /// Lock the resource for reading. /// /// This returns a read guard, very similar to an [`RwLock`][std::sync::RwLock]. - pub fn borrow(&self) -> Option> { + pub fn borrow(&self) -> Option> { let borrow = self.untyped.borrow(); if borrow.is_some() { Some(Ref::map(borrow, |r| unsafe { @@ -387,7 +387,7 @@ impl AtomicResource { /// Lock the resource for read-writing. /// /// This returns a write guard, very similar to an [`RwLock`][std::sync::RwLock]. - pub fn borrow_mut(&self) -> Option> { + pub fn borrow_mut(&self) -> Option> { let borrow = self.untyped.borrow_mut(); if borrow.is_some() { Some(RefMut::map(borrow, |r| unsafe { @@ -415,7 +415,7 @@ impl AtomicResource { /// Borrow the resource, initializing it if it doesn't exist. #[track_caller] - pub fn init_borrow(&self, world: &World) -> Ref { + pub fn init_borrow(&self, world: &World) -> Ref<'_, T> { let map_borrow = |borrow| { // SOUND: we know the schema matches. Ref::map(borrow, |b: &Option| unsafe { @@ -438,7 +438,7 @@ impl AtomicResource { /// Borrow the resource, initializing it if it doesn't exist. #[track_caller] - pub fn init_borrow_mut(&self, world: &World) -> RefMut { + pub fn init_borrow_mut(&self, world: &World) -> RefMut<'_, T> { let mut borrow = self.untyped.borrow_mut(); if unlikely(borrow.is_none()) { *borrow = Some(SchemaBox::new(T::from_world(world))); @@ -500,7 +500,7 @@ impl UntypedResourceSet { /// Init resource with default, and return mutable ref for modification. /// If already exists, returns mutable ref to existing resource. - pub fn init_resource(&mut self) -> RefMut { + pub fn init_resource(&mut self) -> RefMut<'_, T> { if !self.resources.iter().any(|x| x.schema() == T::schema()) { self.insert_resource(T::default()); } @@ -509,7 +509,7 @@ impl UntypedResourceSet { /// Get mutable reference to startup resource if found. #[track_caller] - pub fn resource_mut(&self) -> Option> { + pub fn resource_mut(&self) -> Option> { let res = self.resources.iter().find(|x| x.schema() == T::schema())?; let borrow = res.borrow_mut(); diff --git a/framework_crates/bones_ecs/src/stage.rs b/framework_crates/bones_ecs/src/stage.rs index 40b90f4961..f5a4db2c86 100644 --- a/framework_crates/bones_ecs/src/stage.rs +++ b/framework_crates/bones_ecs/src/stage.rs @@ -155,13 +155,13 @@ impl SystemStagesBuilder { /// Init startup resource with default, and return mutable ref for modification. /// If already exists, returns mutable ref to existing resource. - pub fn init_startup_resource(&mut self) -> RefMut { + pub fn init_startup_resource(&mut self) -> RefMut<'_, T> { self.startup_resources.init_resource::() } /// Get mutable reference to startup resource if found. #[track_caller] - pub fn startup_resource_mut(&self) -> Option> { + pub fn startup_resource_mut(&self) -> Option> { self.startup_resources.resource_mut() } } diff --git a/framework_crates/bones_ecs/src/world.rs b/framework_crates/bones_ecs/src/world.rs index e370e6ed9f..437a2b850f 100644 --- a/framework_crates/bones_ecs/src/world.rs +++ b/framework_crates/bones_ecs/src/world.rs @@ -130,7 +130,7 @@ impl World { } /// Initialize a resource of type `T` by inserting it's default value. - pub fn init_resource(&mut self) -> RefMut { + pub fn init_resource(&mut self) -> RefMut<'_, R> { if unlikely(!self.resources.contains::()) { let value = R::from_world(self); self.resources.insert(value); @@ -147,7 +147,7 @@ impl World { /// # Panics /// Panics if the resource does not exist in the store. #[track_caller] - pub fn resource(&self) -> Ref { + pub fn resource(&self) -> Ref<'_, T> { match self.resources.get::() { Some(r) => r, None => panic!( @@ -162,7 +162,7 @@ impl World { /// # Panics /// Panics if the resource does not exist in the store. #[track_caller] - pub fn resource_mut(&self) -> RefMut { + pub fn resource_mut(&self) -> RefMut<'_, T> { match self.resources.get_mut::() { Some(r) => r, None => panic!( @@ -174,12 +174,12 @@ impl World { } /// Borrow a resource from the world, if it exists. - pub fn get_resource(&self) -> Option> { + pub fn get_resource(&self) -> Option> { self.resources.get() } /// Borrow a resource from the world, if it exists. - pub fn get_resource_mut(&self) -> Option> { + pub fn get_resource_mut(&self) -> Option> { self.resources.get_mut() } @@ -187,7 +187,7 @@ impl World { /// # Panics /// Panics if the component store does not exist in the world. #[track_caller] - pub fn component(&self) -> Ref> { + pub fn component(&self) -> Ref<'_, ComponentStore> { self.components.get::().borrow() } @@ -195,7 +195,7 @@ impl World { /// # Panics /// Panics if the component store does not exist in the world. #[track_caller] - pub fn component_mut(&self) -> RefMut> { + pub fn component_mut(&self) -> RefMut<'_, ComponentStore> { self.components.get::().borrow_mut() } diff --git a/framework_crates/bones_framework/src/params.rs b/framework_crates/bones_framework/src/params.rs index 109885221f..4089b7fef0 100644 --- a/framework_crates/bones_framework/src/params.rs +++ b/framework_crates/bones_framework/src/params.rs @@ -85,7 +85,7 @@ impl<'a, T: HasSchema> SystemParam for Packs<'a, T> { impl Packs<'_, T> { /// Get the typed asset pack roots iterator. - pub fn iter(&self) -> PacksIter { + pub fn iter(&self) -> PacksIter<'_, T> { PacksIter { asset_server: &self.asset_server, asset_packs_iter: self.asset_server.packs().iter(), diff --git a/framework_crates/bones_lib/src/lib.rs b/framework_crates/bones_lib/src/lib.rs index c7454b342d..234309e30f 100644 --- a/framework_crates/bones_lib/src/lib.rs +++ b/framework_crates/bones_lib/src/lib.rs @@ -127,12 +127,12 @@ impl SessionBuilder { /// /// Note: The resource is not actually initialized in World until first step of [`SystemStages`]. /// To mutate or inspect a resource inserted by another [`SessionPlugin`] during session build, use [`SessionBuilder::resource_mut`]. - pub fn init_resource(&mut self) -> RefMut { + pub fn init_resource(&mut self) -> RefMut<'_, T> { self.stages.init_startup_resource::() } /// Get mutable reference to a resource if it exists. - pub fn resource_mut(&self) -> Option> { + pub fn resource_mut(&self) -> Option> { self.stages.startup_resource_mut::() } @@ -430,7 +430,7 @@ impl Game { } #[track_caller] /// Get the shared resource of a given type out of this [`Game`]s shared resources. - pub fn shared_resource(&self) -> Option> { + pub fn shared_resource(&self) -> Option> { let res = self .shared_resources .iter() @@ -449,7 +449,7 @@ impl Game { #[track_caller] /// Get the shared resource of a given type out of this [`Game`]s shared resources. - pub fn shared_resource_mut(&self) -> Option> { + pub fn shared_resource_mut(&self) -> Option> { let res = self .shared_resources .iter() @@ -477,7 +477,7 @@ impl Game { /// Initialize a resource that will be shared across game sessions using it's [`Default`] value /// if it is not already initialized, and borrow it for modification. - pub fn init_shared_resource(&mut self) -> RefMut { + pub fn init_shared_resource(&mut self) -> RefMut<'_, T> { if !self .shared_resources .iter() @@ -854,12 +854,12 @@ impl Sessions { } /// Mutably iterate over sessions. - pub fn iter_mut(&mut self) -> std::collections::hash_map::IterMut { + pub fn iter_mut(&mut self) -> std::collections::hash_map::IterMut<'_, Ustr, Session> { self.map.iter_mut() } /// Iterate over sessions. - pub fn iter(&self) -> std::collections::hash_map::Iter { + pub fn iter(&self) -> std::collections::hash_map::Iter<'_, Ustr, Session> { self.map.iter() } diff --git a/framework_crates/bones_lib/src/reset.rs b/framework_crates/bones_lib/src/reset.rs index dce8f4ea78..48178fe430 100644 --- a/framework_crates/bones_lib/src/reset.rs +++ b/framework_crates/bones_lib/src/reset.rs @@ -25,7 +25,7 @@ impl ResetWorld { } /// Get a mutable reference to a reset resource if found. - pub fn reset_resource_mut(&self) -> Option> { + pub fn reset_resource_mut(&self) -> Option> { self.reset_resources.resource_mut::() } diff --git a/framework_crates/bones_schema/src/alloc/map.rs b/framework_crates/bones_schema/src/alloc/map.rs index 90168a3a66..0821e5d0b4 100644 --- a/framework_crates/bones_schema/src/alloc/map.rs +++ b/framework_crates/bones_schema/src/alloc/map.rs @@ -173,14 +173,17 @@ impl SchemaMap { /// Panics if the schema of the key doesn't match. #[inline] #[track_caller] - pub fn get_ref(&self, key: SchemaRef) -> Option { + pub fn get_ref(&self, key: SchemaRef) -> Option> { self.try_get_ref(key).unwrap() } /// Get an untyped reference to an item in the map. /// # Errors /// Errors if the schema of the key doesn't match. - pub fn try_get_ref(&self, key: SchemaRef) -> Result, SchemaMismatchError> { + pub fn try_get_ref( + &self, + key: SchemaRef, + ) -> Result>, SchemaMismatchError> { if key.schema() != self.key_schema { Err(SchemaMismatchError) } else { @@ -191,7 +194,7 @@ impl SchemaMap { /// # Safety /// The key's schema must match this map's key schema. - pub unsafe fn get_ref_unchecked(&self, key: SchemaRef) -> Option { + pub unsafe fn get_ref_unchecked(&self, key: SchemaRef) -> Option> { let Some(hash_fn) = &self.key_schema.hash_fn else { panic!("Key schema doesn't implement hash"); }; @@ -221,7 +224,7 @@ impl SchemaMap { /// Panics if the schema of the key doesn't match. #[inline] #[track_caller] - pub fn get_ref_mut(&mut self, key: SchemaRef) -> Option { + pub fn get_ref_mut(&mut self, key: SchemaRef) -> Option> { self.try_get_ref_mut(key).unwrap() } @@ -231,7 +234,7 @@ impl SchemaMap { pub fn try_get_ref_mut( &mut self, key: SchemaRef, - ) -> Result, SchemaMismatchError> { + ) -> Result>, SchemaMismatchError> { if key.schema() != self.key_schema { Err(SchemaMismatchError) } else { @@ -242,7 +245,7 @@ impl SchemaMap { /// # Safety /// The key's schema must match this map's key schema. - pub unsafe fn get_ref_unchecked_mut(&mut self, key: SchemaRef) -> Option { + pub unsafe fn get_ref_unchecked_mut(&mut self, key: SchemaRef) -> Option> { let Some(hash_fn) = &self.key_schema.hash_fn else { panic!("Key schema doesn't implement hash"); }; @@ -435,7 +438,7 @@ type SchemaMapIterMut<'iter> = std::iter::Map< impl SchemaMap { /// Iterate over entries in the map. #[allow(clippy::type_complexity)] - pub fn iter(&self) -> SchemaMapIter { + pub fn iter(&self) -> SchemaMapIter<'_> { fn map_fn<'a>( (key, value): (&'a SchemaBox, &'a SchemaBox), ) -> (SchemaRef<'a>, SchemaRef<'a>) { @@ -446,7 +449,7 @@ impl SchemaMap { /// Iterate over entries in the map. #[allow(clippy::type_complexity)] - pub fn iter_mut(&mut self) -> SchemaMapIterMut { + pub fn iter_mut(&mut self) -> SchemaMapIterMut<'_> { fn map_fn<'a>( (key, value): (&'a SchemaBox, &'a mut SchemaBox), ) -> (SchemaRef<'a>, SchemaRefMut<'a>) { @@ -460,10 +463,10 @@ impl SchemaMap { pub fn keys( &self, ) -> std::iter::Map< - hash_map::Keys, + hash_map::Keys<'_, SchemaBox, SchemaBox>, for<'a> fn(&'a SchemaBox) -> SchemaRef<'a>, > { - fn map_fn(key: &SchemaBox) -> SchemaRef { + fn map_fn(key: &SchemaBox) -> SchemaRef<'_> { key.as_ref() } self.map.keys().map(map_fn) @@ -474,10 +477,10 @@ impl SchemaMap { pub fn values( &self, ) -> std::iter::Map< - hash_map::Values, + hash_map::Values<'_, SchemaBox, SchemaBox>, for<'a> fn(&'a SchemaBox) -> SchemaRef<'a>, > { - fn map_fn(key: &SchemaBox) -> SchemaRef { + fn map_fn(key: &SchemaBox) -> SchemaRef<'_> { key.as_ref() } self.map.values().map(map_fn) @@ -488,10 +491,10 @@ impl SchemaMap { pub fn values_mut( &mut self, ) -> std::iter::Map< - hash_map::ValuesMut, + hash_map::ValuesMut<'_, SchemaBox, SchemaBox>, for<'a> fn(&'a mut SchemaBox) -> SchemaRefMut<'a>, > { - fn map_fn(key: &mut SchemaBox) -> SchemaRefMut { + fn map_fn(key: &mut SchemaBox) -> SchemaRefMut<'_> { key.as_mut() } self.map.values_mut().map(map_fn) @@ -664,7 +667,7 @@ type SMapIterMut<'iter, K, V> = std::iter::Map< impl SMap { /// Iterate over entries in the map. #[allow(clippy::type_complexity)] - pub fn iter(&self) -> SMapIter { + pub fn iter(&self) -> SMapIter<'_, K, V> { fn map_fn<'a, K: HasSchema, V: HasSchema>( (key, value): (&'a SchemaBox, &'a SchemaBox), ) -> (&'a K, &'a V) { @@ -681,7 +684,7 @@ impl SMap { /// Iterate over entries in the map. #[allow(clippy::type_complexity)] - pub fn iter_mut(&mut self) -> SMapIterMut { + pub fn iter_mut(&mut self) -> SMapIterMut<'_, K, V> { fn map_fn<'a, K: HasSchema, V: HasSchema>( (key, value): (&'a SchemaBox, &'a mut SchemaBox), ) -> (&'a K, &'a mut V) { @@ -700,7 +703,7 @@ impl SMap { #[allow(clippy::type_complexity)] pub fn keys( &self, - ) -> std::iter::Map, for<'a> fn(&'a SchemaBox) -> &'a K> + ) -> std::iter::Map, for<'a> fn(&'a SchemaBox) -> &'a K> { fn map_fn(key: &SchemaBox) -> &K { // SOUND: SMap ensures key schema always match @@ -713,8 +716,10 @@ impl SMap { #[allow(clippy::type_complexity)] pub fn values( &self, - ) -> std::iter::Map, for<'a> fn(&'a SchemaBox) -> &'a V> - { + ) -> std::iter::Map< + hash_map::Values<'_, SchemaBox, SchemaBox>, + for<'a> fn(&'a SchemaBox) -> &'a V, + > { fn map_fn(value: &SchemaBox) -> &V { // SOUND: SMap ensures value schema always matches. unsafe { value.as_ref().cast_into_unchecked() } @@ -727,7 +732,7 @@ impl SMap { pub fn values_mut( &mut self, ) -> std::iter::Map< - hash_map::ValuesMut, + hash_map::ValuesMut<'_, SchemaBox, SchemaBox>, for<'a> fn(&'a mut SchemaBox) -> &'a mut V, > { fn map_fn(value: &mut SchemaBox) -> &mut V { diff --git a/framework_crates/bones_schema/src/alloc/type_datas.rs b/framework_crates/bones_schema/src/alloc/type_datas.rs index c7b7ad463e..73193d9f8b 100644 --- a/framework_crates/bones_schema/src/alloc/type_datas.rs +++ b/framework_crates/bones_schema/src/alloc/type_datas.rs @@ -58,7 +58,7 @@ impl TypeDatas { } /// Borrow data from the store, if it exists. - pub fn get_ref(&self, id: SchemaId) -> Option { + pub fn get_ref(&self, id: SchemaId) -> Option> { for data in self.0.iter() { if data.schema().id() == id { return Some(data.as_ref()); diff --git a/framework_crates/bones_schema/src/alloc/vec.rs b/framework_crates/bones_schema/src/alloc/vec.rs index 03bd2a2fb5..88e5975546 100644 --- a/framework_crates/bones_schema/src/alloc/vec.rs +++ b/framework_crates/bones_schema/src/alloc/vec.rs @@ -275,12 +275,12 @@ impl SchemaVec { } /// Iterate over values in the vec - pub fn iter(&self) -> SchemaVecIter { + pub fn iter(&self) -> SchemaVecIter<'_> { SchemaVecIter { vec: self, idx: 0 } } /// Iterate mutably over values in the vec - pub fn iter_mut(&mut self) -> SchemaVecIterMut { + pub fn iter_mut(&mut self) -> SchemaVecIterMut<'_> { SchemaVecIterMut { vec: self, idx: 0 } } @@ -568,7 +568,7 @@ impl SVec { } /// Iterate over references to the items in the vec. - pub fn iter(&self) -> SVecIter { + pub fn iter(&self) -> SVecIter<'_, T> { SVecIter { vec: self, idx: 0, @@ -577,7 +577,7 @@ impl SVec { } /// Iterate over mutable references to the items in the vec. - pub fn iter_mut(&mut self) -> SVecIterMut { + pub fn iter_mut(&mut self) -> SVecIterMut<'_, T> { SVecIterMut { idx: 0, end: self.len() as isize - 1, diff --git a/framework_crates/bones_schema/src/ptr.rs b/framework_crates/bones_schema/src/ptr.rs index 93e428cabb..fde4d15603 100644 --- a/framework_crates/bones_schema/src/ptr.rs +++ b/framework_crates/bones_schema/src/ptr.rs @@ -148,7 +148,7 @@ impl<'pointer> SchemaRef<'pointer> { } /// Get a helper to access the inner without consuming this reference. - fn access_borrowed(&self) -> SchemaRefAccess { + fn access_borrowed(&self) -> SchemaRefAccess<'_> { SchemaRefAccess::new_borrowed(self) } @@ -413,7 +413,7 @@ impl<'a> StructRefAccess<'a> { } /// Interate over the fields on the struct. - pub fn fields(&self) -> StructRefFieldIter { + pub fn fields(&self) -> StructRefFieldIter<'_> { StructRefFieldIter { ptr: self.0, field_idx: 0, @@ -829,7 +829,7 @@ impl<'pointer> SchemaRefMut<'pointer> { } /// Get the reference to a field. - pub fn field<'a, I: Into>>(&mut self, field_idx: I) -> Option { + pub fn field<'a, I: Into>>(&mut self, field_idx: I) -> Option> { Some( self.access_mut() .field(field_idx) @@ -842,7 +842,7 @@ impl<'pointer> SchemaRefMut<'pointer> { pub fn field_path<'a, I: IntoIterator>>( &mut self, path: I, - ) -> Option { + ) -> Option> { self.access_mut() .field_path(path) .map(|x| x.into_schema_ref_mut()) @@ -1041,7 +1041,7 @@ impl<'pointer> SchemaRefMutAccess<'pointer> { } /// Borrow this [`SchemaRefMutAccess`] as a [`SchemaRefAccess`]. - pub fn as_ref(&self) -> SchemaRefAccess { + pub fn as_ref(&self) -> SchemaRefAccess<'_> { match self { SchemaRefMutAccess::Struct(s) => SchemaRefAccess::Struct(StructRefAccess(s.0.as_ref())), SchemaRefMutAccess::Vec(v) => SchemaRefAccess::Vec(SchemaVecAccess { @@ -1281,7 +1281,7 @@ pub enum PrimitiveRefMut<'a> { impl<'ptr> PrimitiveRefMut<'ptr> { /// Convert to an immutable [`PrimitiveRef`]. - pub fn as_ref(&self) -> PrimitiveRef { + pub fn as_ref(&self) -> PrimitiveRef<'_> { match self { PrimitiveRefMut::Bool(b) => PrimitiveRef::Bool(b), PrimitiveRefMut::U8(n) => PrimitiveRef::U8(n), @@ -1874,7 +1874,7 @@ impl<'a> IntoIterator for FieldPath<&'a str> { fn flt(x: &&str) -> bool { !x.is_empty() } - fn mp(x: &str) -> FieldIdx { + fn mp(x: &str) -> FieldIdx<'_> { x.parse::() .map(FieldIdx::Idx) .unwrap_or(FieldIdx::Name(x)) @@ -1890,7 +1890,7 @@ impl IntoIterator for FieldPath { fn flt(x: &&str) -> bool { !x.is_empty() } - fn mp(x: &str) -> FieldIdx { + fn mp(x: &str) -> FieldIdx<'_> { x.parse::() .map(FieldIdx::Idx) .unwrap_or(FieldIdx::Name(x)) diff --git a/framework_crates/bones_schema/src/schema.rs b/framework_crates/bones_schema/src/schema.rs index 0514f193e7..02ff8d503d 100644 --- a/framework_crates/bones_schema/src/schema.rs +++ b/framework_crates/bones_schema/src/schema.rs @@ -86,7 +86,7 @@ pub unsafe trait HasSchema: Sync + Send + 'static { } /// Converts a reference of `T` to a [`SchemaRef`] - fn as_schema_ref(&self) -> SchemaRef + fn as_schema_ref(&self) -> SchemaRef<'_> where Self: Sized, { @@ -94,7 +94,7 @@ pub unsafe trait HasSchema: Sync + Send + 'static { } /// Converts a reference of `T` to a [`SchemaRefMut`] - fn as_schema_mut(&mut self) -> SchemaRefMut + fn as_schema_mut(&mut self) -> SchemaRefMut<'_> where Self: Sized, { diff --git a/framework_crates/bones_scripting/src/lua/bindings/ecsref.rs b/framework_crates/bones_scripting/src/lua/bindings/ecsref.rs index 3dc2b29c67..52d30e8f4d 100644 --- a/framework_crates/bones_scripting/src/lua/bindings/ecsref.rs +++ b/framework_crates/bones_scripting/src/lua/bindings/ecsref.rs @@ -32,7 +32,7 @@ impl<'gc> FromValue<'gc> for &'gc EcsRef { impl EcsRef { /// Borrow the value pointed to by the [`EcsRef`] - pub fn borrow(&self) -> EcsRefBorrow { + pub fn borrow(&self) -> EcsRefBorrow<'_> { EcsRefBorrow { borrow: self.data.borrow(), path: self.path, @@ -40,7 +40,7 @@ impl EcsRef { } /// Mutably borrow the value pointed to by the [`EcsRef`] - pub fn borrow_mut(&self) -> EcsRefBorrowMut { + pub fn borrow_mut(&self) -> EcsRefBorrowMut<'_> { EcsRefBorrowMut { borrow: self.data.borrow_mut(), path: self.path, @@ -64,7 +64,7 @@ pub struct EcsRefBorrow<'a> { impl EcsRefBorrow<'_> { /// Get the [`SchemaRef`]. - pub fn schema_ref(&self) -> Result { + pub fn schema_ref(&self) -> Result, EcsRefBorrowError> { let b = self.borrow.schema_ref()?; let b = b .field_path(FieldPath(self.path)) @@ -81,7 +81,7 @@ pub struct EcsRefBorrowMut<'a> { impl EcsRefBorrowMut<'_> { /// Get the [`SchemaRef`]. - pub fn schema_ref_mut(&mut self) -> Result { + pub fn schema_ref_mut(&mut self) -> Result, EcsRefBorrowError> { let b = self.borrow.schema_ref_mut()?; let b = b .into_field_path(FieldPath(self.path)) @@ -151,7 +151,7 @@ impl EcsRefBorrowKind<'_> { /// /// Will return none if the value does not exist, such as an unloaded asset or a component /// that is not set for a given entity. - pub fn schema_ref(&self) -> Result { + pub fn schema_ref(&self) -> Result, EcsRefBorrowError> { match self { EcsRefBorrowKind::Resource(r) => Ok(r .as_ref() @@ -199,7 +199,7 @@ impl EcsRefBorrowMutKind<'_> { /// /// Will return none if the value does not exist, such as an unloaded asset or a component /// that is not set for a given entity. - pub fn schema_ref_mut(&mut self) -> Result { + pub fn schema_ref_mut(&mut self) -> Result, EcsRefBorrowError> { match self { EcsRefBorrowMutKind::Resource(r) => Ok(r .as_mut() @@ -224,7 +224,7 @@ impl EcsRefBorrowMutKind<'_> { impl EcsRefData { /// Immutably borrow the data. - pub fn borrow(&self) -> EcsRefBorrowKind { + pub fn borrow(&self) -> EcsRefBorrowKind<'_> { match self { EcsRefData::Resource(resource) => { let b = resource.as_ref().borrow(); @@ -249,7 +249,7 @@ impl EcsRefData { } /// Mutably borrow the data. - pub fn borrow_mut(&self) -> EcsRefBorrowMutKind { + pub fn borrow_mut(&self) -> EcsRefBorrowMutKind<'_> { match self { EcsRefData::Resource(resource) => { let b = resource.borrow_mut();