Skip to content

Commit

Permalink
Fix paths in SystemData macro (#232)
Browse files Browse the repository at this point in the history
* fix paths in SystemData macro

* remove leading ::

* revert unintended changes

* add missed path

* fix examples and tests without default features
  • Loading branch information
IsseW authored Nov 27, 2023
1 parent 12d482d commit 5450bf3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/async.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate shred;

use shred::{DispatcherBuilder, Read, ResourceId, System, SystemData, World, Write};
use shred::{DispatcherBuilder, Read, System, SystemData, World, Write};

#[derive(Debug, Default)]
struct ResA;
Expand Down
4 changes: 3 additions & 1 deletion examples/derive_bundle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use shred::{Read, ResourceId, SystemData, World, Write};
#[cfg(not(feature = "shred-derive"))]
use shred::ResourceId;
use shred::{Read, SystemData, World, Write};

#[derive(Debug, Default)]
struct ResA;
Expand Down
2 changes: 1 addition & 1 deletion examples/generic_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate shred_derive;

use std::fmt::Debug;

use shred::{Read, Resource, ResourceId, SystemData, World, Write};
use shred::{Read, Resource, SystemData, Write};

trait Hrtb<'a> {}

Expand Down
4 changes: 3 additions & 1 deletion examples/seq_dispatch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use shred::{DispatcherBuilder, Read, ResourceId, System, SystemData, World, Write};
#[cfg(not(feature = "shred-derive"))]
use shred::ResourceId;
use shred::{DispatcherBuilder, Read, System, SystemData, World, Write};

#[derive(Debug, Default)]
struct ResA;
Expand Down
22 changes: 11 additions & 11 deletions shred-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,35 @@ fn impl_system_data(ast: &DeriveInput) -> proc_macro2::TokenStream {

quote! {
impl #impl_generics
SystemData< #impl_fetch_lt >
shred::SystemData< #impl_fetch_lt >
for #name #ty_generics #where_clause
{
fn setup(world: &mut World) {
fn setup(world: &mut shred::World) {
#(
<#tys as SystemData> :: setup(world);
<#tys as shred::SystemData> :: setup(world);
)*
}

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

fn reads() -> Vec<ResourceId> {
fn reads() -> Vec<shred::ResourceId> {
let mut r = Vec::new();

#( {
let mut reads = <#tys as SystemData> :: reads();
let mut reads = <#tys as shred::SystemData> :: reads();
r.append(&mut reads);
} )*

r
}

fn writes() -> Vec<ResourceId> {
fn writes() -> Vec<shred::ResourceId> {
let mut r = Vec::new();

#( {
let mut writes = <#tys as SystemData> :: writes();
let mut writes = <#tys as shred::SystemData> :: writes();
r.append(&mut writes);
} )*

Expand All @@ -107,7 +107,7 @@ fn gen_identifiers(fields: &Punctuated<Field, Comma>) -> Vec<Ident> {
/// Adds a `SystemData<'lt>` bound on each of the system data types.
fn constrain_system_data_types(clause: &mut WhereClause, fetch_lt: &Lifetime, tys: &[Type]) {
for ty in tys.iter() {
let where_predicate: WherePredicate = parse_quote!(#ty : SystemData< #fetch_lt >);
let where_predicate: WherePredicate = parse_quote!(#ty : shred::SystemData< #fetch_lt >);
clause.predicates.push(where_predicate);
}
}
Expand Down Expand Up @@ -138,13 +138,13 @@ fn gen_from_body(ast: &Data, name: &Ident) -> (proc_macro2::TokenStream, Vec<Typ

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

quote! {
#name ( #( #fetch ),* )
Expand Down
6 changes: 3 additions & 3 deletions tests/dispatch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use shred::{
Dispatcher, DispatcherBuilder, Read, ResourceId, RunningTime, System, SystemData, World, Write,
};
#[cfg(not(feature = "shred-derive"))]
use shred::ResourceId;
use shred::{Dispatcher, DispatcherBuilder, Read, RunningTime, System, SystemData, World, Write};

fn sleep_short() {
use std::{thread::sleep, time::Duration};
Expand Down

0 comments on commit 5450bf3

Please sign in to comment.