Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion framework_crates/bones_asset/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 14 additions & 11 deletions framework_crates/bones_asset/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ impl AssetServer {
}

/// Borrow a [`LoadedAsset`] associated to the given handle.
pub fn get_asset_untyped(&self, handle: UntypedHandle) -> Option<MapRef<Cid, LoadedAsset>> {
pub fn get_asset_untyped(&self, handle: UntypedHandle) -> Option<MapRef<'_, Cid, LoadedAsset>> {
let cid = self.store.asset_ids.get(&handle)?;
self.store.assets.get(&cid)
}
Expand All @@ -815,7 +815,7 @@ impl AssetServer {
pub fn get_asset_untyped_mut(
&self,
handle: UntypedHandle,
) -> Option<MapRefMut<Cid, LoadedAsset>> {
) -> Option<MapRefMut<'_, Cid, LoadedAsset>> {
let cid = self.store.asset_ids.get(&handle)?;
self.store.assets.get_mut(&cid)
}
Expand All @@ -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<AssetPack> {
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<T: HasSchema>(&self) -> MappedMapRef<Cid, LoadedAsset, T> {
pub fn root<T: HasSchema>(&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<Cid, LoadedAsset, SchemaBox> {
pub fn untyped_root(&self) -> MappedMapRef<'_, Cid, LoadedAsset, SchemaBox> {
self.get_untyped(self.core().root)
}

Expand All @@ -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<T: HasSchema>(&self, handle: Handle<T>) -> MappedMapRef<Cid, LoadedAsset, T> {
pub fn get<T: HasSchema>(&self, handle: Handle<T>) -> 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")
Expand All @@ -864,7 +864,10 @@ impl AssetServer {
///
/// Panics if the asset is not loaded.
#[track_caller]
pub fn get_untyped(&self, handle: UntypedHandle) -> MappedMapRef<Cid, LoadedAsset, SchemaBox> {
pub fn get_untyped(
&self,
handle: UntypedHandle,
) -> MappedMapRef<'_, Cid, LoadedAsset, SchemaBox> {
self.try_get_untyped(handle).unwrap()
}

Expand All @@ -877,7 +880,7 @@ impl AssetServer {
pub fn get_untyped_mut(
&self,
handle: UntypedHandle,
) -> MappedMapRefMut<Cid, LoadedAsset, SchemaBox> {
) -> MappedMapRefMut<'_, Cid, LoadedAsset, SchemaBox> {
self.try_get_untyped_mut(handle).unwrap()
}

Expand Down Expand Up @@ -918,7 +921,7 @@ impl AssetServer {
pub fn try_get_untyped(
&self,
handle: UntypedHandle,
) -> Option<MappedMapRef<Cid, LoadedAsset, SchemaBox>> {
) -> Option<MappedMapRef<'_, Cid, LoadedAsset, SchemaBox>> {
let cid = self.store.asset_ids.get(&handle)?;
Some(MapRef::map(self.store.assets.get(&cid).unwrap(), |x| {
&x.data
Expand All @@ -929,7 +932,7 @@ impl AssetServer {
pub fn try_get_untyped_mut(
&self,
handle: UntypedHandle,
) -> Option<MappedMapRefMut<Cid, LoadedAsset, SchemaBox>> {
) -> Option<MappedMapRefMut<'_, Cid, LoadedAsset, SchemaBox>> {
let cid = self.store.asset_ids.get_mut(&handle)?;
Some(MapRefMut::map(
self.store.assets.get_mut(&cid).unwrap(),
Expand Down Expand Up @@ -968,7 +971,7 @@ impl AssetServer {
pub fn get_mut<T: HasSchema>(
&mut self,
handle: &Handle<T>,
) -> MappedMapRefMut<Cid, LoadedAsset, T> {
) -> MappedMapRefMut<'_, Cid, LoadedAsset, T> {
let cid = self
.store
.asset_ids
Expand Down
2 changes: 1 addition & 1 deletion framework_crates/bones_bevy_renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bones::Ref<bones::AssetServer>> {
pub fn asset_server(&self) -> Option<bones::Ref<'_, bones::AssetServer>> {
self.0.shared_resource()
}
}
Expand Down
28 changes: 14 additions & 14 deletions framework_crates/bones_ecs/src/components/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,28 +170,28 @@ 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<BitSetVec>) -> ComponentBitsetIterator<T>;
fn iter_with_bitset(&self, bitset: Rc<BitSetVec>) -> ComponentBitsetIterator<'_, T>;

/// 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_optional(
&self,
bitset: Rc<BitSetVec>,
) -> ComponentBitsetOptionalIterator<T>;
) -> 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<BitSetVec>) -> ComponentBitsetIteratorMut<T>;
fn iter_mut_with_bitset(&mut self, bitset: Rc<BitSetVec>) -> ComponentBitsetIteratorMut<'_, T>;

/// Iterates mutably 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_optional(
&mut self,
bitset: Rc<BitSetVec>,
) -> ComponentBitsetOptionalIteratorMut<T>;
) -> ComponentBitsetOptionalIteratorMut<'_, T>;

/// Get bitset of [`ComponentStore`] / implementor.
fn bitset(&self) -> &BitSetVec;
Expand All @@ -207,7 +207,7 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore<T> {
/// Gets an immutable reference to the component if there is exactly one instance of it.
fn get_single_with_bitset(&self, bitset: Rc<BitSetVec>) -> Result<&T, QuerySingleError> {
// SOUND: we know the schema matches.
fn map<T>(r: SchemaRef) -> &T {
fn map<T>(r: SchemaRef<'_>) -> &T {
unsafe { r.cast_into_unchecked() }
}
self.untyped.get_single_with_bitset(bitset).map(map)
Expand All @@ -219,7 +219,7 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore<T> {
bitset: Rc<BitSetVec>,
) -> Result<&mut T, QuerySingleError> {
// SOUND: we know the schema matches.
fn map<T>(r: SchemaRefMut) -> &mut T {
fn map<T>(r: SchemaRefMut<'_>) -> &mut T {
unsafe { r.cast_into_mut_unchecked() }
}
self.untyped.get_single_with_bitset_mut(bitset).map(map)
Expand All @@ -229,9 +229,9 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore<T> {
/// indicates the indices of entities.
/// Slower than `iter()` but allows joining between multiple component types.
#[inline]
fn iter_with_bitset(&self, bitset: Rc<BitSetVec>) -> ComponentBitsetIterator<T> {
fn iter_with_bitset(&self, bitset: Rc<BitSetVec>) -> ComponentBitsetIterator<'_, T> {
// SOUND: we know the schema matches.
fn map<T>(r: SchemaRef) -> &T {
fn map<T>(r: SchemaRef<'_>) -> &T {
unsafe { r.cast_into_unchecked() }
}
self.untyped.iter_with_bitset(bitset).map(map)
Expand All @@ -244,9 +244,9 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore<T> {
fn iter_with_bitset_optional(
&self,
bitset: Rc<BitSetVec>,
) -> ComponentBitsetOptionalIterator<T> {
) -> ComponentBitsetOptionalIterator<'_, T> {
// SOUND: we know the schema matches.
fn map<T>(r: Option<SchemaRef>) -> Option<&T> {
fn map<T>(r: Option<SchemaRef<'_>>) -> Option<&T> {
r.map(|r| unsafe { r.cast_into_unchecked() })
}
self.untyped.iter_with_bitset_optional(bitset).map(map)
Expand All @@ -256,9 +256,9 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore<T> {
/// 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<BitSetVec>) -> ComponentBitsetIteratorMut<T> {
fn iter_mut_with_bitset(&mut self, bitset: Rc<BitSetVec>) -> ComponentBitsetIteratorMut<'_, T> {
// SOUND: we know the schema matches.
fn map<T>(r: SchemaRefMut) -> &mut T {
fn map<T>(r: SchemaRefMut<'_>) -> &mut T {
unsafe { r.cast_into_mut_unchecked() }
}

Expand All @@ -272,9 +272,9 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore<T> {
fn iter_mut_with_bitset_optional(
&mut self,
bitset: Rc<BitSetVec>,
) -> ComponentBitsetOptionalIteratorMut<T> {
) -> ComponentBitsetOptionalIteratorMut<'_, T> {
// SOUND: we know the schema matches.
fn map<T>(r: Option<SchemaRefMut>) -> Option<&mut T> {
fn map<T>(r: Option<SchemaRefMut<'_>>) -> Option<&mut T> {
r.map(|r| unsafe { r.cast_into_mut_unchecked() })
}
self.untyped.iter_mut_with_bitset_optional(bitset).map(map)
Expand Down
18 changes: 9 additions & 9 deletions framework_crates/bones_ecs/src/components/untyped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SchemaRef> {
pub fn get_ref(&self, entity: Entity) -> Option<SchemaRef<'_>> {
let idx = entity.index() as usize;
self.get_idx(idx)
}

fn get_idx(&self, idx: usize) -> Option<SchemaRef> {
fn get_idx(&self, idx: usize) -> Option<SchemaRef<'_>> {
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) };
Expand Down Expand Up @@ -377,7 +377,7 @@ impl UntypedComponentStore {
pub fn get_many_ref_mut<const N: usize>(
&mut self,
entities: [Entity; N],
) -> [Option<SchemaRefMut>; N] {
) -> [Option<SchemaRefMut<'_>>; N] {
// Sort a copy of the passed in entities list.
let mut sorted = entities;
sorted.sort_unstable();
Expand Down Expand Up @@ -494,7 +494,7 @@ impl UntypedComponentStore {
pub fn get_single_with_bitset(
&self,
bitset: Rc<BitSetVec>,
) -> Result<SchemaRef, QuerySingleError> {
) -> Result<SchemaRef<'_>, QuerySingleError> {
if self.bitset().bit_count() == 0 || bitset.bit_count() == 0 {
// Both bitsets are empty so there are no matches
return Err(QuerySingleError::NoEntities);
Expand All @@ -520,7 +520,7 @@ impl UntypedComponentStore {
pub fn get_single_with_bitset_mut(
&mut self,
bitset: Rc<BitSetVec>,
) -> Result<SchemaRefMut, QuerySingleError> {
) -> Result<SchemaRefMut<'_>, QuerySingleError> {
if self.bitset().bit_count() == 0 || bitset.bit_count() == 0 {
// Both bitsets are empty so there are no matches
return Err(QuerySingleError::NoEntities);
Expand Down Expand Up @@ -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<BitSetVec>) -> UntypedComponentBitsetIterator {
pub fn iter_with_bitset(&self, bitset: Rc<BitSetVec>) -> UntypedComponentBitsetIterator<'_> {
UntypedComponentBitsetIterator {
current_id: 0,
components: self,
Expand All @@ -580,7 +580,7 @@ impl UntypedComponentStore {
pub fn iter_mut_with_bitset(
&mut self,
bitset: Rc<BitSetVec>,
) -> UntypedComponentBitsetIteratorMut {
) -> UntypedComponentBitsetIteratorMut<'_> {
UntypedComponentBitsetIteratorMut {
current_id: 0,
components: self,
Expand All @@ -593,7 +593,7 @@ impl UntypedComponentStore {
pub fn iter_with_bitset_optional(
&self,
bitset: Rc<BitSetVec>,
) -> UntypedComponentOptionalBitsetIterator {
) -> UntypedComponentOptionalBitsetIterator<'_> {
let components_count = self.bitset.bit_count();
let query_count = bitset.bit_count();
UntypedComponentOptionalBitsetIterator {
Expand All @@ -613,7 +613,7 @@ impl UntypedComponentStore {
pub fn iter_mut_with_bitset_optional(
&mut self,
bitset: Rc<BitSetVec>,
) -> UntypedComponentOptionalBitsetIteratorMut {
) -> UntypedComponentOptionalBitsetIteratorMut<'_> {
let components_count = self.bitset.bit_count();
let query_count = bitset.bit_count();
UntypedComponentOptionalBitsetIteratorMut {
Expand Down
7 changes: 5 additions & 2 deletions framework_crates/bones_ecs/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,10 @@ impl Entities {
/// }
/// }
/// ```
pub fn iter_with<Q: QueryItem>(&self, query: Q) -> EntitiesIterWith<<Q as QueryItem>::Iter> {
pub fn iter_with<Q: QueryItem>(
&self,
query: Q,
) -> EntitiesIterWith<'_, <Q as QueryItem>::Iter> {
let mut bitset = self.bitset().clone();
query.apply_bitset(&mut bitset);
let bitset = Rc::new(bitset);
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions framework_crates/bones_ecs/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ impl UntypedResource {

/// Borrow the resource.
#[track_caller]
pub fn borrow(&self) -> Ref<Option<SchemaBox>> {
pub fn borrow(&self) -> Ref<'_, Option<SchemaBox>> {
self.cell.borrow()
}

/// Mutably borrow the resource.
#[track_caller]
pub fn borrow_mut(&self) -> RefMut<Option<SchemaBox>> {
pub fn borrow_mut(&self) -> RefMut<'_, Option<SchemaBox>> {
self.cell.borrow_mut()
}

Expand Down Expand Up @@ -253,7 +253,7 @@ impl Resources {

/// Borrow a resource.
#[track_caller]
pub fn get<T: HasSchema>(&self) -> Option<Ref<T>> {
pub fn get<T: HasSchema>(&self) -> Option<Ref<'_, T>> {
let b = self.untyped.get(T::schema()).borrow();
if b.is_some() {
Some(Ref::map(b, |b| unsafe {
Expand All @@ -266,7 +266,7 @@ impl Resources {

/// Borrow a resource.
#[track_caller]
pub fn get_mut<T: HasSchema>(&self) -> Option<RefMut<T>> {
pub fn get_mut<T: HasSchema>(&self) -> Option<RefMut<'_, T>> {
let b = self.untyped.get(T::schema()).borrow_mut();
if b.is_some() {
Some(RefMut::map(b, |b| unsafe {
Expand Down Expand Up @@ -373,7 +373,7 @@ impl<T: HasSchema> AtomicResource<T> {
/// Lock the resource for reading.
///
/// This returns a read guard, very similar to an [`RwLock`][std::sync::RwLock].
pub fn borrow(&self) -> Option<Ref<T>> {
pub fn borrow(&self) -> Option<Ref<'_, T>> {
let borrow = self.untyped.borrow();
if borrow.is_some() {
Some(Ref::map(borrow, |r| unsafe {
Expand All @@ -387,7 +387,7 @@ impl<T: HasSchema> AtomicResource<T> {
/// 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<RefMut<T>> {
pub fn borrow_mut(&self) -> Option<RefMut<'_, T>> {
let borrow = self.untyped.borrow_mut();
if borrow.is_some() {
Some(RefMut::map(borrow, |r| unsafe {
Expand Down Expand Up @@ -415,7 +415,7 @@ impl<T: HasSchema + FromWorld> AtomicResource<T> {

/// Borrow the resource, initializing it if it doesn't exist.
#[track_caller]
pub fn init_borrow(&self, world: &World) -> Ref<T> {
pub fn init_borrow(&self, world: &World) -> Ref<'_, T> {
let map_borrow = |borrow| {
// SOUND: we know the schema matches.
Ref::map(borrow, |b: &Option<SchemaBox>| unsafe {
Expand All @@ -438,7 +438,7 @@ impl<T: HasSchema + FromWorld> AtomicResource<T> {

/// Borrow the resource, initializing it if it doesn't exist.
#[track_caller]
pub fn init_borrow_mut(&self, world: &World) -> RefMut<T> {
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)));
Expand Down Expand Up @@ -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<T: HasSchema + Default>(&mut self) -> RefMut<T> {
pub fn init_resource<T: HasSchema + Default>(&mut self) -> RefMut<'_, T> {
if !self.resources.iter().any(|x| x.schema() == T::schema()) {
self.insert_resource(T::default());
}
Expand All @@ -509,7 +509,7 @@ impl UntypedResourceSet {

/// Get mutable reference to startup resource if found.
#[track_caller]
pub fn resource_mut<T: HasSchema>(&self) -> Option<RefMut<T>> {
pub fn resource_mut<T: HasSchema>(&self) -> Option<RefMut<'_, T>> {
let res = self.resources.iter().find(|x| x.schema() == T::schema())?;
let borrow = res.borrow_mut();

Expand Down
Loading