Skip to content

Commit

Permalink
Merge pull request #752 from amethyst/enable_fmt
Browse files Browse the repository at this point in the history
Enable fmt
  • Loading branch information
xMAC94x authored Jul 2, 2022
2 parents f07c484 + d0fea2c commit f1392fa
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 106 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ jobs:
if: matrix.toolchain == 'stable' && matrix.os == 'ubuntu-latest'

# run rustfmt and clippy checks, but only once
#- run: cargo +nightly fmt --all -- --check
# if: matrix.toolchain == 'stable' && matrix.os == 'ubuntu-latest'
- run: cargo +nightly fmt --all -- --check
if: matrix.toolchain == 'stable' && matrix.os == 'ubuntu-latest'

#- run: cargo +nightly clippy -Z unstable-options --workspace --all-targets --all-features
# if: matrix.toolchain == 'stable' && matrix.os == 'ubuntu-latest'
Expand Down
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
hard_tabs = false
merge_imports = true
imports_granularity = "Crate"
reorder_impl_items = true
use_field_init_shorthand = true
use_try_shorthand = true
Expand Down
27 changes: 9 additions & 18 deletions benches/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,21 @@ fn world_build(b: &mut Bencher) {
}

fn create_now(b: &mut Bencher) {
b.iter_with_large_setup(
World::new,
|mut w| {
w.create_entity().build();
},
);
b.iter_with_large_setup(World::new, |mut w| {
w.create_entity().build();
});
}

fn create_now_with_storage(b: &mut Bencher) {
b.iter_with_large_setup(
create_world,
|mut w| {
w.create_entity().with(CompInt(0)).build();
},
);
b.iter_with_large_setup(create_world, |mut w| {
w.create_entity().with(CompInt(0)).build();
});
}

fn create_pure(b: &mut Bencher) {
b.iter_with_large_setup(
World::new,
|w| {
w.entities().create();
},
);
b.iter_with_large_setup(World::new, |w| {
w.entities().create();
});
}

fn delete_now(b: &mut Bencher) {
Expand Down
6 changes: 4 additions & 2 deletions examples/saveload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ extern crate ron;
extern crate serde;
extern crate specs;

use std::{convert::Infallible, fmt};
use ron::ser::PrettyConfig;
use std::{convert::Infallible, fmt};

use specs::{
prelude::*,
Expand Down Expand Up @@ -157,7 +157,9 @@ fn main() {
let mut buf = Vec::new();
let mut config = PrettyConfig::default();
config.struct_names = true;
let mut ser = ron::ser::Serializer::with_options(&mut buf, Some(config), Default::default()).unwrap();
let mut ser =
ron::ser::Serializer::with_options(&mut buf, Some(config), Default::default())
.unwrap();

// For serialization we use the
// [`SerializeComponents`](struct.SerializeComponents.html)-trait's `serialize`
Expand Down
12 changes: 4 additions & 8 deletions specs-derive/src/impl_saveload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,9 @@ fn saveload_tuple_struct(
let field_ids = saveload_fields
.iter()
.enumerate()
.map(|(i, _field_meta)| {
Index {
index: i as u32,
span: data.struct_token.span,
}
.map(|(i, _field_meta)| Index {
index: i as u32,
span: data.struct_token.span,
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -595,9 +593,7 @@ fn replace_entity_type(ty: &mut Type) {
}
}

fn single_parse_outer_from_args(
input: syn::parse::ParseStream,
) -> Result<Attribute, syn::Error> {
fn single_parse_outer_from_args(input: syn::parse::ParseStream) -> Result<Attribute, syn::Error> {
Ok(Attribute {
pound_token: syn::token::Pound {
spans: [input.span()],
Expand Down
6 changes: 1 addition & 5 deletions src/join/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,7 @@ impl<J: Join> std::iter::Iterator for JoinIter<J> {
///
/// // add some entities to our world
/// for _ in 0..10 {
/// let entity = world
/// .create_entity()
/// .with(Position)
/// .with(Collider)
/// .build();
/// let entity = world.create_entity().with(Position).with(Collider).build();
/// }
///
/// // check for collisions between entities
Expand Down
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![warn(missing_docs)]
#![cfg_attr(feature = "nightly", feature(generic_associated_types, associated_type_defaults))]
#![cfg_attr(
feature = "nightly",
feature(generic_associated_types, associated_type_defaults)
)]

//! # SPECS Parallel ECS
//!
Expand Down Expand Up @@ -207,9 +210,9 @@ pub mod world;

pub use hibitset::BitSet;
pub use shred::{
Accessor, AccessorCow, BatchAccessor, BatchController, BatchUncheckedWorld,
Dispatcher, DispatcherBuilder, Read, ReadExpect, RunNow,
RunningTime, StaticAccessor, System, SystemData, World, Write, WriteExpect,
Accessor, AccessorCow, BatchAccessor, BatchController, BatchUncheckedWorld, Dispatcher,
DispatcherBuilder, Read, ReadExpect, RunNow, RunningTime, StaticAccessor, System, SystemData,
World, Write, WriteExpect,
};
pub use shrev::ReaderId;

Expand All @@ -232,4 +235,4 @@ pub use crate::{
};

#[cfg(feature = "nightly")]
pub use crate::storage::DerefFlaggedStorage;
pub use crate::storage::DerefFlaggedStorage;
2 changes: 1 addition & 1 deletion src/saveload/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub trait MarkerAllocator<M: Marker>: Resource {

new
} else {
return None
return None;
};
Some((storage.get(entity).unwrap(), new))
}
Expand Down
1 change: 0 additions & 1 deletion src/saveload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//! to identify entities even if local ids are different. The allocation
//! of these ids is what `MarkerAllocator`s are responsible for. For an example,
//! see the docs for the `Marker` trait.
//!

use std::convert::Infallible;

Expand Down
3 changes: 2 additions & 1 deletion src/saveload/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ mod marker_test {
let mut buf = Vec::new();
let mut config = ron::ser::PrettyConfig::default();
config.struct_names = true;
let mut ser = ron::ser::Serializer::with_options(&mut buf, Some(config), Default::default()).unwrap();
let mut ser =
ron::ser::Serializer::with_options(&mut buf, Some(config), Default::default()).unwrap();

world.exec(
|(ents, comp_a, comp_b, markers, _alloc): (
Expand Down
19 changes: 14 additions & 5 deletions src/storage/deref_flagged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::{
use shrev::EventChannel;

/// Wrapper storage that tracks modifications, insertions, and removals of
/// components through an `EventChannel`, in a similar manner to `FlaggedStorage`.
/// components through an `EventChannel`, in a similar manner to
/// `FlaggedStorage`.
///
/// Unlike `FlaggedStorage`, this storage uses a wrapper type for mutable
/// accesses that only emits modification events when the component is actually
Expand Down Expand Up @@ -55,7 +56,10 @@ where
}

impl<C: Component, T: UnprotectedStorage<C>> UnprotectedStorage<C> for DerefFlaggedStorage<C, T> {
type AccessMut<'a> where T: 'a = FlaggedAccessMut<'a, <T as UnprotectedStorage<C>>::AccessMut<'a>, C>;
type AccessMut<'a>
where
T: 'a,
= FlaggedAccessMut<'a, <T as UnprotectedStorage<C>>::AccessMut<'a>, C>;

unsafe fn clean<B>(&mut self, has: B)
where
Expand Down Expand Up @@ -123,14 +127,19 @@ pub struct FlaggedAccessMut<'a, A, C> {
}

impl<'a, A, C> Deref for FlaggedAccessMut<'a, A, C>
where A: Deref<Target = C>
where
A: Deref<Target = C>,
{
type Target = C;
fn deref(&self) -> &Self::Target { self.access.deref() }

fn deref(&self) -> &Self::Target {
self.access.deref()
}
}

impl<'a, A, C> DerefMut for FlaggedAccessMut<'a, A, C>
where A: DerefMut<Target = C>
where
A: DerefMut<Target = C>,
{
fn deref_mut(&mut self) -> &mut Self::Target {
if self.emit {
Expand Down
5 changes: 4 additions & 1 deletion src/storage/flagged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ where

impl<C: Component, T: UnprotectedStorage<C>> UnprotectedStorage<C> for FlaggedStorage<C, T> {
#[cfg(feature = "nightly")]
type AccessMut<'a> where T: 'a = <T as UnprotectedStorage<C>>::AccessMut<'a>;
type AccessMut<'a>
where
T: 'a,
= <T as UnprotectedStorage<C>>::AccessMut<'a>;

unsafe fn clean<B>(&mut self, has: B)
where
Expand Down
29 changes: 20 additions & 9 deletions src/storage/generic.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[cfg(feature = "nightly")]
use std::ops::DerefMut;
use crate::storage::UnprotectedStorage;
use crate::{
storage::{InsertResult, ReadStorage, WriteStorage, AccessMutReturn},
storage::{AccessMutReturn, InsertResult, ReadStorage, WriteStorage},
world::{Component, Entity},
};
#[cfg(feature = "nightly")]
use crate::storage::UnprotectedStorage;
use std::ops::DerefMut;

pub struct Seal;

Expand Down Expand Up @@ -88,7 +88,9 @@ pub trait GenericWriteStorage {
type Component: Component;
/// The wrapper through with mutable access of a component is performed.
#[cfg(feature = "nightly")]
type AccessMut<'a>: DerefMut<Target=Self::Component> where Self: 'a;
type AccessMut<'a>: DerefMut<Target = Self::Component>
where
Self: 'a;

/// Get mutable access to an `Entity`s component
fn get_mut(&mut self, entity: Entity) -> Option<AccessMutReturn<'_, Self::Component>>;
Expand All @@ -97,7 +99,10 @@ pub trait GenericWriteStorage {
/// exist, it is automatically created using `Default::default()`.
///
/// Returns None if the entity is dead.
fn get_mut_or_default(&mut self, entity: Entity) -> Option<AccessMutReturn<'_, Self::Component>>
fn get_mut_or_default(
&mut self,
entity: Entity,
) -> Option<AccessMutReturn<'_, Self::Component>>
where
Self::Component: Default;

Expand All @@ -115,9 +120,12 @@ impl<'a, T> GenericWriteStorage for WriteStorage<'a, T>
where
T: Component,
{
type Component = T;
#[cfg(feature = "nightly")]
type AccessMut<'b> where Self: 'b = <<T as Component>::Storage as UnprotectedStorage<T>>::AccessMut<'b>;
type AccessMut<'b>
where
Self: 'b,
= <<T as Component>::Storage as UnprotectedStorage<T>>::AccessMut<'b>;
type Component = T;

fn get_mut(&mut self, entity: Entity) -> Option<AccessMutReturn<'_, T>> {
WriteStorage::get_mut(self, entity)
Expand Down Expand Up @@ -153,9 +161,12 @@ impl<'a: 'b, 'b, T> GenericWriteStorage for &'b mut WriteStorage<'a, T>
where
T: Component,
{
type Component = T;
#[cfg(feature = "nightly")]
type AccessMut<'c> where Self: 'c = <<T as Component>::Storage as UnprotectedStorage<T>>::AccessMut<'c>;
type AccessMut<'c>
where
Self: 'c,
= <<T as Component>::Storage as UnprotectedStorage<T>>::AccessMut<'c>;
type Component = T;

fn get_mut(&mut self, entity: Entity) -> Option<AccessMutReturn<'_, T>> {
WriteStorage::get_mut(*self, entity)
Expand Down
22 changes: 12 additions & 10 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//! Component storage types, implementations for component joins, etc.

#[cfg(feature = "nightly")]
pub use self::deref_flagged::{DerefFlaggedStorage, FlaggedAccessMut};
pub use self::{
data::{ReadStorage, WriteStorage},
entry::{Entries, OccupiedEntry, StorageEntry, VacantEntry},
flagged::FlaggedStorage,
generic::{GenericReadStorage, GenericWriteStorage},
restrict::{
ImmutableParallelRestriction, MutableParallelRestriction, RestrictedStorage,
SequentialRestriction, PairedStorage
ImmutableParallelRestriction, MutableParallelRestriction, PairedStorage, RestrictedStorage,
SequentialRestriction,
},
storages::{
BTreeStorage, DefaultVecStorage, DenseVecStorage, HashMapStorage, NullStorage, VecStorage,
},
track::{ComponentEvent, Tracked},
};
#[cfg(feature = "nightly")]
pub use self::deref_flagged::{DerefFlaggedStorage, FlaggedAccessMut};

use self::storages::SliceAccess;

Expand All @@ -39,11 +39,11 @@ use crate::{
use self::drain::Drain;

mod data;
#[cfg(feature = "nightly")]
mod deref_flagged;
mod drain;
mod entry;
mod flagged;
#[cfg(feature = "nightly")]
mod deref_flagged;
mod generic;
mod restrict;
mod storages;
Expand Down Expand Up @@ -328,7 +328,7 @@ where
}

/// Tries to mutate the data associated with an `Entity`.
pub fn get_mut(&mut self, e: Entity) -> Option<AccessMutReturn<'_, T> > {
pub fn get_mut(&mut self, e: Entity) -> Option<AccessMutReturn<'_, T>> {
if self.data.mask.contains(e.id()) && self.entities.is_alive(e) {
// SAFETY: We checked the mask, so all invariants are met.
Some(unsafe { self.data.inner.get_mut(e.id()) })
Expand Down Expand Up @@ -507,7 +507,9 @@ where
pub trait UnprotectedStorage<T>: TryDefault {
/// The wrapper through with mutable access of a component is performed.
#[cfg(feature = "nightly")]
type AccessMut<'a>: DerefMut<Target=T> where Self: 'a;
type AccessMut<'a>: DerefMut<Target = T>
where
Self: 'a;

/// Clean the storage given a bitset with bits set for valid indices.
/// Allows us to safely drop the storage.
Expand Down Expand Up @@ -581,8 +583,8 @@ pub trait UnprotectedStorage<T>: TryDefault {
unsafe fn remove(&mut self, id: Index) -> T;

/// Drops the data associated with an `Index`.
/// This could be used when a more efficient implementation for it exists than `remove` when the data
/// is no longer needed.
/// This could be used when a more efficient implementation for it exists
/// than `remove` when the data is no longer needed.
/// Defaults to simply calling `remove`.
///
/// # Safety
Expand Down
4 changes: 2 additions & 2 deletions src/storage/restrict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::join::Join;
#[cfg(feature = "parallel")]
use crate::join::ParJoin;
use crate::{
storage::{MaskedStorage, Storage, UnprotectedStorage, AccessMutReturn},
storage::{AccessMutReturn, MaskedStorage, Storage, UnprotectedStorage},
world::{Component, EntitiesRes, Entity, Index},
};

Expand Down Expand Up @@ -248,7 +248,7 @@ where
{
/// Gets the component related to the current entry without checking whether
/// the storage has it or not.
pub fn get_mut_unchecked(&mut self) -> AccessMutReturn<'_, C> {
pub fn get_mut_unchecked(&mut self) -> AccessMutReturn<'_, C> {
unsafe { self.storage.borrow_mut().get_mut(self.index) }
}
}
Expand Down
Loading

0 comments on commit f1392fa

Please sign in to comment.