Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - untyped APIs for components and resources #4447

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d0d8d37
bevy_ecs: untyped API to access components
jakobhellermann Jan 27, 2022
ae98499
bevy_ecs: untyped API to access resources
jakobhellermann Apr 9, 2022
d13bbe5
validate nonsend correctness for dynamic resource APIs
jakobhellermann Apr 9, 2022
497685c
bevy_ecs: add insert_resource_by_id
jakobhellermann Apr 9, 2022
9bcbcae
bevy_ecs: untyped API to init components
jakobhellermann Apr 9, 2022
612fd92
bevy_ecs: add Components::iter
jakobhellermann Apr 7, 2022
64f81af
remove TypeId and is_send_and_sync from ComponentDescriptor::new_with…
jakobhellermann Apr 10, 2022
3201c1a
add docs
jakobhellermann Apr 10, 2022
3493688
add tests
jakobhellermann Apr 10, 2022
0dc2f4c
add #[inline]
jakobhellermann Apr 10, 2022
6efc899
two more safety comments
jakobhellermann Apr 10, 2022
1698a7b
fix broken link
jakobhellermann Apr 10, 2022
1db081f
move methods in separate `impl` block so rustdoc deprioritizes them,
jakobhellermann Apr 12, 2022
77c8235
move warning notes to second paragraph
jakobhellermann Apr 19, 2022
720e60b
move resource_by_id methods on world to separate impl block
jakobhellermann Apr 19, 2022
f0280d7
add test for ComponentDescriptor::new_with_layout
jakobhellermann Apr 19, 2022
ce2b0d0
add World::remove_resource_by_id
jakobhellermann Apr 19, 2022
a3f2c6d
add some #[inline] attributes
jakobhellermann Apr 19, 2022
7b6045a
Merge branch 'main' into bevy-ecs-dynamic
jakobhellermann May 1, 2022
974075d
use Ptr types
jakobhellermann May 1, 2022
06de78c
use UnsafeCellDeref::deref_mut
jakobhellermann May 2, 2022
5fa60ef
trigger CI
jakobhellermann May 3, 2022
b2a3fb8
Merge branch 'main' into bevy-ecs-dynamic
jakobhellermann May 3, 2022
1253338
add missing function
jakobhellermann May 3, 2022
b9263ae
Merge branch 'main' into bevy-ecs-dynamic
jakobhellermann May 7, 2022
5bd27d7
Merge branch 'main' into bevy-ecs-dynamic
jakobhellermann May 9, 2022
396d437
add world.get_by_id and world.get_mut_by_id
jakobhellermann May 9, 2022
faac9f4
validate ComponentIds before passing them to unsafe functions expecti…
jakobhellermann May 9, 2022
6051bc7
clean up docs
jakobhellermann May 13, 2022
756d009
cargo fmt
jakobhellermann May 17, 2022
cc784d2
Update crates/bevy_ecs/src/change_detection.rs
jakobhellermann May 17, 2022
b22ec5a
change EntityRef::get_by_id to return 'w ptr, like its typed variant
jakobhellermann May 17, 2022
b02170a
Merge branch 'main' into bevy-ecs-dynamic
jakobhellermann May 17, 2022
041688e
update to optional drop pointer in ComponentDescriptor
jakobhellermann May 17, 2022
3965a1b
Merge branch 'main' into bevy-ecs-dynamic
jakobhellermann May 24, 2022
9547a9b
fix new_with_layout constructor in test
jakobhellermann May 24, 2022
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
Prev Previous commit
Next Next commit
add #[inline]
  • Loading branch information
jakobhellermann committed Apr 10, 2022
commit 0dc2f4c49949c1a9656a964b28649bd4a638fa94
3 changes: 3 additions & 0 deletions crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl<'w> EntityRef<'w> {
/// You should prefer to use the typed API where possible and only
/// use this in cases where the actual component types are not known at
/// compile time.
#[inline]
pub fn get_by_id(&self, component_id: ComponentId) -> Option<*const ()> {
jakobhellermann marked this conversation as resolved.
Show resolved Hide resolved
unsafe {
get_component(self.world, component_id, self.entity, self.location)
Expand Down Expand Up @@ -180,6 +181,7 @@ impl<'w> EntityMut<'w> {
/// You should prefer to use the typed API where possible and only
/// use this in cases where the actual component types are not known at
/// compile time.
#[inline]
pub fn get_by_id(&self, component_id: ComponentId) -> Option<*const ()> {
unsafe {
get_component(self.world, component_id, self.entity, self.location)
Expand All @@ -201,6 +203,7 @@ impl<'w> EntityMut<'w> {
/// You should prefer to use the typed API where possible and only
/// use this in cases where the actual component types are not known at
/// compile time.
#[inline]
pub fn get_mut_by_id(&mut self, component_id: ComponentId) -> Option<MutUntyped<'_>> {
// SAFE: world access is unique and entity location is valid
unsafe {
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,7 @@ impl World {
///
/// You should always prefer to use the [`World::get_resource`] where possible and only
/// use this in cases where the actual types are not known at compile time.
jakobhellermann marked this conversation as resolved.
Show resolved Hide resolved
#[inline]
pub fn get_resource_by_id(&self, component_id: ComponentId) -> Option<*const ()> {
let info = self.components.get_info(component_id)?;
if !info.is_send_and_sync() {
Expand All @@ -1127,6 +1128,7 @@ impl World {
///
/// You should always prefer to use the [`World::get_resource_mut`] where possible and only
/// use this in cases where the actual types are not known at compile time.
#[inline]
pub fn get_resource_mut_by_id(&mut self, component_id: ComponentId) -> Option<MutUntyped<'_>> {
let info = self.components.get_info(component_id)?;
if !info.is_send_and_sync() {
Expand Down