Skip to content

Commit

Permalink
StorageType parameter removed from ComponentDescriptor::new_resource (#…
Browse files Browse the repository at this point in the history
…3495)

# Objective

Remove the `StorageType` parameter from `ComponentDescriptor::new_resource` as discussed in #3361.

- fixes #3361

## Solution

- Parameter removed.
- Basic docs added.

## Note

Left a [comment](#3361 (comment)) about `SparseStorage` being the more reasonable choice.



Co-authored-by: r4gus <[email protected]>
  • Loading branch information
r4gus and r4gus committed Dec 30, 2021
1 parent 3ac55f0 commit c641a90
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/bevy_ecs/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,15 @@ impl ComponentDescriptor {
}
}

pub fn new_resource<T: Resource>(storage_type: StorageType) -> Self {
/// Create a new `ComponentDescriptor` for a resource.
///
/// The [`StorageType`] for resources is always [`TableStorage`].
pub fn new_resource<T: Resource>() -> Self {
Self {
name: std::any::type_name::<T>().to_string(),
storage_type,
// PERF: `SparseStorage` may actually be a more
// reasonable choice as `storage_type` for resources.
storage_type: StorageType::Table,
is_send_and_sync: true,
type_id: Some(TypeId::of::<T>()),
layout: Layout::new::<T>(),
Expand Down Expand Up @@ -308,7 +313,7 @@ impl Components {
// SAFE: The [`ComponentDescriptor`] matches the [`TypeId`]
unsafe {
self.get_or_insert_resource_with(TypeId::of::<T>(), || {
ComponentDescriptor::new_resource::<T>(StorageType::default())
ComponentDescriptor::new_resource::<T>()
})
}
}
Expand Down

0 comments on commit c641a90

Please sign in to comment.