Skip to content

Commit

Permalink
Add test for when Send is implemented for PairedStorageWriteShared
Browse files Browse the repository at this point in the history
  • Loading branch information
Imberflur committed Jul 23, 2023
1 parent 6b74393 commit 5aa5abf
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/storage/restrict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,68 @@ where
{
}

/// Compile test for when `Send` is implemented.
/// ```rust,compile_fail
/// use specs::prelude::*;
///
/// struct Pos(f32);
/// impl Component for Pos {
/// type Storage = FlaggedStorage<Self>;
/// }
///
/// fn main() {
/// let mut world = World::new();
/// world.register::<Pos>();
/// world.create_entity().with(Pos(0.0)).build();
/// world.create_entity().with(Pos(1.6)).build();
/// world.create_entity().with(Pos(5.4)).build();
/// let mut pos = world.write_storage::<Pos>();
///
/// let mut restricted_pos = pos.restrict_mut();
/// let mut joined = (&mut restricted_pos).join();
/// let mut a = joined.next().unwrap();
/// let mut b = joined.next().unwrap();
/// // unsound since Pos::Storage isn't a DistinctStorage
/// std::thread::scope(|s| {
/// s.spawn(move || {
/// a.get_mut();
/// });
/// });
/// b.get_mut();
/// }
/// ```
/// Should compile since `VecStorage` is a `DistinctStorage`.
/// ```rust
/// use specs::prelude::*;
///
/// struct Pos(f32);
/// impl Component for Pos {
/// type Storage = VecStorage<Self>;
/// }
///
/// fn main() {
/// let mut world = World::new();
/// world.register::<Pos>();
/// world.create_entity().with(Pos(0.0)).build();
/// world.create_entity().with(Pos(1.6)).build();
/// world.create_entity().with(Pos(5.4)).build();
/// let mut pos = world.write_storage::<Pos>();
///
/// let mut restricted_pos = pos.restrict_mut();
/// let mut joined = (&mut restricted_pos).join();
/// let mut a = joined.next().unwrap();
/// let mut b = joined.next().unwrap();
/// // sound since Pos::Storage is a DistinctStorage
/// std::thread::scope(|s| {
/// s.spawn(move || {
/// a.get_mut();
/// });
/// });
/// b.get_mut();
/// }
/// ```
fn _dummy() {}

/// Pairs a storage with an index, meaning that the index is guaranteed to
/// exist.
///
Expand Down

0 comments on commit 5aa5abf

Please sign in to comment.