Skip to content

Commit

Permalink
Merge amethyst#114
Browse files Browse the repository at this point in the history
114: Some cleanup r=torkleyy a=torkleyy

cc amethyst#111 

Co-authored-by: Thomas Schaller <[email protected]>
  • Loading branch information
bors[bot] and torkleyy committed Mar 29, 2019
2 parents 8474fe2 + 3e832a3 commit cba9136
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rust:
- nightly
- beta
- stable
- 1.30.0
- 1.32.0

branches:
only:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Please see [the benchmark](benches/bench.rs) for a bigger (and useful) example.

### Required Rust version

`1.30 stable`
`1.32 stable`

## Features

Expand Down
10 changes: 5 additions & 5 deletions shred-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ fn impl_system_data(ast: &DeriveInput) -> proc_macro2::TokenStream {
SystemData< #impl_fetch_lt >
for #name #ty_generics #where_clause
{
fn setup(res: &mut World) {
fn setup(world: &mut World) {
#(
<#tys as SystemData> :: setup(res);
<#tys as SystemData> :: setup(world);
)*
}

fn fetch(res: & #impl_fetch_lt World) -> Self {
fn fetch(world: & #impl_fetch_lt World) -> Self {
#fetch_return
}

Expand Down Expand Up @@ -130,13 +130,13 @@ fn gen_from_body(ast: &Data, name: &Ident) -> (proc_macro2::TokenStream, Vec<Typ

quote! {
#name {
#( #identifiers: SystemData::fetch(res) ),*
#( #identifiers: SystemData::fetch(world) ),*
}
}
}
DataType::Tuple => {
let count = tys.len();
let fetch = vec![quote! { SystemData::fetch(res) }; count];
let fetch = vec![quote! { SystemData::fetch(world) }; count];

quote! {
#name ( #( #fetch ),* )
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rayon::ThreadPool;

use dispatch::dispatcher::ThreadLocal;
use dispatch::stage::Stage;
use res::World;
use world::World;

pub fn new_async<'a, R>(
res: R,
Expand Down
4 changes: 2 additions & 2 deletions src/dispatch/dispatcher.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use smallvec::SmallVec;

use dispatch::stage::Stage;
use res::World;
use system::RunNow;
use world::World;

/// The dispatcher struct, allowing
/// systems to be executed in parallel.
Expand Down Expand Up @@ -150,8 +150,8 @@ pub fn new_dispatcher<'a, 'b>(
#[cfg(test)]
mod tests {
use dispatch::builder::DispatcherBuilder;
use res::*;
use system::*;
use world::*;

#[derive(Default)]
struct Res(i32);
Expand Down
10 changes: 5 additions & 5 deletions src/dispatch/par_seq.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::borrow::Borrow;

use dispatch::util::check_intersection;
use res::{ResourceId, World};
use system::RunNow;
use system::System;
use world::{ResourceId, World};

use rayon::{join, ThreadPool};

Expand Down Expand Up @@ -187,7 +187,7 @@ impl<H> Par<H, Nil> {
/// #
/// # let pool = ThreadPool::new(Default::default()).unwrap();
/// #
/// # let mut res = World::new();
/// # let mut world = World::new();
/// let x = 5u8;
///
/// let mut dispatcher = ParSeq::new(
Expand All @@ -206,7 +206,7 @@ impl<H> Par<H, Nil> {
/// &pool,
/// );
///
/// dispatcher.dispatch(&mut res);
/// dispatcher.dispatch(&mut world);
/// # }
/// ```
pub struct ParSeq<P, T> {
Expand All @@ -226,13 +226,13 @@ where
ParSeq { run, pool }
}

/// Sets up `res` for `dispatch`ing.
/// Sets up `world` for `dispatch`ing.
/// This will add default values for required resources by calling `System::setup`.
pub fn setup(&mut self, res: &mut World) {
self.run.setup(res);
}

/// Dispatches the systems using `res`.
/// Dispatches the systems using `world`.
/// This doesn't call any virtual functions.
///
/// Please note that this method assumes that no resource
Expand Down
4 changes: 2 additions & 2 deletions src/dispatch/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//!
//! for stage in stages {
//! stage.for_each_group(|group| for system in group {
//! system.run(res);
//! system.run(world);
//! });
//! }
//!
Expand All @@ -38,8 +38,8 @@ use smallvec::SmallVec;

use dispatch::dispatcher::{SystemExecSend, SystemId};
use dispatch::util::check_intersection;
use res::{ResourceId, World};
use system::{RunningTime, System};
use world::{ResourceId, World};

const MAX_SYSTEMS_PER_GROUP: usize = 5;

Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ pub mod cell;

mod dispatch;
mod meta;
mod res;
mod system;
mod world;

#[cfg(feature = "parallel")]
pub use dispatch::AsyncDispatcher;
pub use dispatch::{Dispatcher, DispatcherBuilder};
#[cfg(feature = "parallel")]
pub use dispatch::{Par, ParSeq, RunWithPool, Seq};
pub use meta::{CastFrom, MetaIter, MetaIterMut, MetaTable};
pub use res::{
DefaultProvider, Entry, Fetch, FetchMut, PanicHandler, Read, ReadExpect, Resource, ResourceId,
World, SetupHandler, Write, WriteExpect,
};
pub use system::{
Accessor, AccessorCow, DynamicSystemData, RunNow, RunningTime, StaticAccessor, System,
SystemData,
};
pub use world::{
DefaultProvider, Entry, Fetch, FetchMut, PanicHandler, Read, ReadExpect, Resource, ResourceId,
World, SetupHandler, Write, WriteExpect,
};
16 changes: 8 additions & 8 deletions src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,17 @@ where
/// }
/// }
///
/// let mut res = World::new();
/// let mut world = World::new();
///
/// res.insert(ImplementorA(3));
/// res.insert(ImplementorB(1));
/// world.insert(ImplementorA(3));
/// world.insert(ImplementorB(1));
///
/// let mut table = MetaTable::<Object>::new();
/// table.register(&ImplementorA(31415)); // Can just be some instance of type `&ImplementorA`.
/// table.register(&ImplementorB(27182));
///
/// {
/// let mut iter = table.iter(&mut res);
/// let mut iter = table.iter(&mut world);
/// assert_eq!(iter.next().unwrap().method1(), 3);
/// assert_eq!(iter.next().unwrap().method1(), 1);
/// }
Expand Down Expand Up @@ -273,8 +273,8 @@ impl<T: ?Sized> MetaTable<T> {
}
}

/// Tries to convert `res` to a trait object of type `&T`.
/// If `res` doesn't have an implementation for `T` (or it wasn't registered),
/// Tries to convert `world` to a trait object of type `&T`.
/// If `world` doesn't have an implementation for `T` (or it wasn't registered),
/// this will return `None`.
pub fn get<'a>(&self, res: &'a Resource) -> Option<&'a T> {
unsafe {
Expand All @@ -284,8 +284,8 @@ impl<T: ?Sized> MetaTable<T> {
}
}

/// Tries to convert `res` to a trait object of type `&mut T`.
/// If `res` doesn't have an implementation for `T` (or it wasn't registered),
/// Tries to convert `world` to a trait object of type `&mut T`.
/// If `world` doesn't have an implementation for `T` (or it wasn't registered),
/// this will return `None`.
pub fn get_mut<'a>(&self, res: &'a Resource) -> Option<&'a mut T> {
unsafe {
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/res/entry.rs → src/world/entry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::marker::PhantomData;

use cell::TrustCell;
use res::{FetchMut, Resource, ResourceId};
use world::{FetchMut, Resource, ResourceId};

type StdEntry<'a, K, V> = hashbrown::hash_map::Entry<'a, K, V, hashbrown::hash_map::DefaultHashBuilder>;

Expand All @@ -16,9 +16,9 @@ type StdEntry<'a, K, V> = hashbrown::hash_map::Entry<'a, K, V, hashbrown::hash_m
/// #[derive(Debug)]
/// struct Res(i32);
///
/// let mut res = World::new();
/// let mut world = World::new();
///
/// let value = res.entry().or_insert(Res(4));
/// let value = world.entry().or_insert(Res(4));
/// println!("{:?}", value.0 * 2);
/// ```
pub struct Entry<'a, T: 'a> {
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn create_entry<'a, T>(e: StdEntry<'a, ResourceId, TrustCell<Box<Resource>>>

#[cfg(test)]
mod tests {
use res::World;
use world::World;

#[test]
fn test_entry() {
Expand Down
4 changes: 2 additions & 2 deletions src/res/mod.rs → src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ impl World {
/// # #[derive(Debug)] struct MyRes(i32);
/// use shred::World;
///
/// let mut res = World::new();
/// res.insert(MyRes(5));
/// let mut world = World::new();
/// world.insert(MyRes(5));
/// ```
pub fn insert<R>(&mut self, r: R)
where
Expand Down
File renamed without changes.

0 comments on commit cba9136

Please sign in to comment.