Skip to content

Commit 26e2182

Browse files
jakobhellermannItsDoot
authored andcommitted
bevy_ptr standalone crate (bevyengine#4653)
# Objective The pointer types introduced in bevyengine#3001 are useful not just in `bevy_ecs`, but also in crates like `bevy_reflect` (bevyengine#4475) or even outside of bevy. ## Solution Extract `Ptr<'a>`, `PtrMut<'a>`, `OwnedPtr<'a>`, `ThinSlicePtr<'a, T>` and `UnsafeCellDeref` from `bevy_ecs::ptr` into `bevy_ptr`. **Note:** `bevy_ecs` still reexports the `bevy_ptr` as `bevy_ecs::ptr` so that crates like `bevy_transform` can use the `Bundle` derive without needing to depend on `bevy_ptr` themselves.
1 parent 7da7ea4 commit 26e2182

File tree

18 files changed

+62
-12
lines changed

18 files changed

+62
-12
lines changed

crates/bevy_ecs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ trace = []
1414
default = ["bevy_reflect"]
1515

1616
[dependencies]
17+
bevy_ptr = { path = "../bevy_ptr", version = "0.8.0-dev" }
1718
bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", optional = true }
1819
bevy_tasks = { path = "../bevy_tasks", version = "0.8.0-dev" }
1920
bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }

crates/bevy_ecs/src/bundle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use crate::{
88
archetype::{AddBundle, Archetype, ArchetypeId, Archetypes, ComponentStatus},
99
component::{Component, ComponentId, ComponentTicks, Components, StorageType},
1010
entity::{Entities, Entity, EntityLocation},
11-
ptr::OwningPtr,
1211
storage::{SparseSetIndex, SparseSets, Storages, Table},
1312
};
1413
use bevy_ecs_macros::all_tuples;
14+
use bevy_ptr::OwningPtr;
1515
use std::{any::TypeId, collections::HashMap};
1616

1717
/// An ordered collection of [`Component`]s.

crates/bevy_ecs/src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Types for declaring and storing [`Component`]s.
22
33
use crate::{
4-
ptr::OwningPtr,
54
storage::{SparseSetIndex, Storages},
65
system::Resource,
76
};
87
pub use bevy_ecs_macros::Component;
8+
use bevy_ptr::OwningPtr;
99
use std::{
1010
alloc::Layout,
1111
any::{Any, TypeId},

crates/bevy_ecs/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub mod change_detection;
66
pub mod component;
77
pub mod entity;
88
pub mod event;
9-
pub mod ptr;
109
pub mod query;
1110
#[cfg(feature = "bevy_reflect")]
1211
pub mod reflect;
@@ -15,6 +14,8 @@ pub mod storage;
1514
pub mod system;
1615
pub mod world;
1716

17+
pub use bevy_ptr as ptr;
18+
1819
/// Most commonly used re-exported types.
1920
pub mod prelude {
2021
#[doc(hidden)]

crates/bevy_ecs/src/query/fetch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use crate::{
33
change_detection::Ticks,
44
component::{Component, ComponentId, ComponentStorage, ComponentTicks, StorageType},
55
entity::Entity,
6-
ptr::{ThinSlicePtr, UnsafeCellDeref},
76
query::{debug_checked_unreachable, Access, FilteredAccess},
87
storage::{ComponentSparseSet, Table, Tables},
98
world::{Mut, World},
109
};
1110
use bevy_ecs_macros::all_tuples;
1211
pub use bevy_ecs_macros::WorldQuery;
12+
use bevy_ptr::{ThinSlicePtr, UnsafeCellDeref};
1313
use std::{cell::UnsafeCell, marker::PhantomData};
1414

1515
/// Types that can be queried from a [`World`].

crates/bevy_ecs/src/query/filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::{
22
archetype::{Archetype, ArchetypeComponentId},
33
component::{Component, ComponentId, ComponentStorage, ComponentTicks, StorageType},
44
entity::Entity,
5-
ptr::{ThinSlicePtr, UnsafeCellDeref},
65
query::{
76
debug_checked_unreachable, Access, Fetch, FetchState, FilteredAccess, QueryFetch,
87
ROQueryFetch, WorldQuery, WorldQueryGats,
@@ -11,6 +10,7 @@ use crate::{
1110
world::World,
1211
};
1312
use bevy_ecs_macros::all_tuples;
13+
use bevy_ptr::{ThinSlicePtr, UnsafeCellDeref};
1414
use std::{cell::UnsafeCell, marker::PhantomData};
1515

1616
use super::ReadOnlyFetch;

crates/bevy_ecs/src/storage/blob_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
ptr::NonNull,
55
};
66

7-
use crate::ptr::{OwningPtr, Ptr, PtrMut};
7+
use bevy_ptr::{OwningPtr, Ptr, PtrMut};
88

99
/// A flat, type-erased data storage type
1010
///

crates/bevy_ecs/src/storage/sparse_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::{
22
component::{ComponentId, ComponentInfo, ComponentTicks},
33
entity::Entity,
4-
ptr::{OwningPtr, Ptr},
54
storage::BlobVec,
65
};
6+
use bevy_ptr::{OwningPtr, Ptr};
77
use std::{cell::UnsafeCell, marker::PhantomData};
88

99
#[derive(Debug)]

crates/bevy_ecs/src/storage/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::{
22
component::{ComponentId, ComponentInfo, ComponentTicks, Components},
33
entity::Entity,
4-
ptr::{OwningPtr, Ptr, PtrMut},
54
storage::{BlobVec, SparseSet},
65
};
6+
use bevy_ptr::{OwningPtr, Ptr, PtrMut};
77
use bevy_utils::HashMap;
88
use std::{
99
cell::UnsafeCell,

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::{
55
change_detection::Ticks,
66
component::{Component, ComponentId, ComponentTicks, Components},
77
entity::{Entities, Entity},
8-
ptr::UnsafeCellDeref,
98
query::{
109
Access, FilteredAccess, FilteredAccessSet, QueryFetch, QueryState, ReadOnlyFetch,
1110
WorldQuery,
@@ -15,6 +14,7 @@ use crate::{
1514
};
1615
pub use bevy_ecs_macros::SystemParam;
1716
use bevy_ecs_macros::{all_tuples, impl_param_set};
17+
use bevy_ptr::UnsafeCellDeref;
1818
use std::{
1919
fmt::Debug,
2020
marker::PhantomData,

0 commit comments

Comments
 (0)