From 912916ca33fda70dc3fc412259b9176c73ed78cd Mon Sep 17 00:00:00 2001 From: Isse Date: Tue, 21 Nov 2023 00:30:27 +0100 Subject: [PATCH 1/5] fix paths in SystemData macro --- examples/async.rs | 2 +- examples/derive_bundle.rs | 2 +- examples/generic_derive.rs | 2 +- examples/seq_dispatch.rs | 2 +- examples/thread_local.rs | 2 +- shred-derive/src/lib.rs | 20 ++++++++++---------- src/system.rs | 18 ++++++++++++++++++ tests/dispatch.rs | 4 +--- 8 files changed, 34 insertions(+), 18 deletions(-) diff --git a/examples/async.rs b/examples/async.rs index a69a0f43..d123c188 100644 --- a/examples/async.rs +++ b/examples/async.rs @@ -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; diff --git a/examples/derive_bundle.rs b/examples/derive_bundle.rs index 1a016729..fb4e6ac9 100644 --- a/examples/derive_bundle.rs +++ b/examples/derive_bundle.rs @@ -1,4 +1,4 @@ -use shred::{Read, ResourceId, SystemData, World, Write}; +use shred::{Read, SystemData, World, Write}; #[derive(Debug, Default)] struct ResA; diff --git a/examples/generic_derive.rs b/examples/generic_derive.rs index 6669c778..b029a917 100644 --- a/examples/generic_derive.rs +++ b/examples/generic_derive.rs @@ -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> {} diff --git a/examples/seq_dispatch.rs b/examples/seq_dispatch.rs index 215dd598..ec2cd563 100644 --- a/examples/seq_dispatch.rs +++ b/examples/seq_dispatch.rs @@ -1,4 +1,4 @@ -use shred::{DispatcherBuilder, Read, ResourceId, System, SystemData, World, Write}; +use shred::{DispatcherBuilder, Read, System, SystemData, World, Write}; #[derive(Debug, Default)] struct ResA; diff --git a/examples/thread_local.rs b/examples/thread_local.rs index 51b231bd..c2e3dbcc 100644 --- a/examples/thread_local.rs +++ b/examples/thread_local.rs @@ -1,4 +1,4 @@ -use shred::{DispatcherBuilder, Read, ResourceId, System, SystemData, World, Write}; +use shred::{DispatcherBuilder, Read, System, SystemData, World, Write}; #[derive(Debug, Default)] struct ResA; diff --git a/shred-derive/src/lib.rs b/shred-derive/src/lib.rs index 5eb7041a..351689c4 100644 --- a/shred-derive/src/lib.rs +++ b/shred-derive/src/lib.rs @@ -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 { + 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 { + 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); } )* @@ -138,13 +138,13 @@ fn gen_from_body(ast: &Data, name: &Ident) -> (proc_macro2::TokenStream, Vec { let count = tys.len(); - let fetch = vec![quote! { SystemData::fetch(world) }; count]; + let fetch = vec![quote! { ::shred::SystemData::fetch(world) }; count]; quote! { #name ( #( #fetch ),* ) diff --git a/src/system.rs b/src/system.rs index dca8c78e..e4d77e86 100644 --- a/src/system.rs +++ b/src/system.rs @@ -284,6 +284,11 @@ pub trait SystemData<'a> { /// /// Please note that returning wrong dependencies can lead to a panic. fn writes() -> Vec; + + /// Returns names of retrieved resources. + fn resource_names() -> Vec<&'static str> { + vec![std::any::type_name::()] + } } impl<'a, T> DynamicSystemData<'a> for T @@ -431,6 +436,19 @@ macro_rules! impl_data { r } + + fn resource_names() -> Vec<&'static str> { + #![allow(unused_mut)] + + let mut r = Vec::new(); + + $( { + let mut names = <$ty as SystemData>::resource_names(); + r.append(&mut names); + } )* + + r + } } }; } diff --git a/tests/dispatch.rs b/tests/dispatch.rs index 6eaca2d5..1e0e1d54 100644 --- a/tests/dispatch.rs +++ b/tests/dispatch.rs @@ -1,6 +1,4 @@ -use shred::{ - Dispatcher, DispatcherBuilder, Read, ResourceId, RunningTime, System, SystemData, World, Write, -}; +use shred::{Dispatcher, DispatcherBuilder, Read, RunningTime, System, SystemData, World, Write}; fn sleep_short() { use std::{thread::sleep, time::Duration}; From 9e85e7abf2c3d0e0c616d21f222e48e0d970de91 Mon Sep 17 00:00:00 2001 From: Isse Date: Tue, 21 Nov 2023 21:49:19 +0100 Subject: [PATCH 2/5] remove leading :: --- shred-derive/src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/shred-derive/src/lib.rs b/shred-derive/src/lib.rs index 351689c4..0b3f3c65 100644 --- a/shred-derive/src/lib.rs +++ b/shred-derive/src/lib.rs @@ -58,35 +58,35 @@ fn impl_system_data(ast: &DeriveInput) -> proc_macro2::TokenStream { quote! { impl #impl_generics - ::shred::SystemData< #impl_fetch_lt > + shred::SystemData< #impl_fetch_lt > for #name #ty_generics #where_clause { - fn setup(world: &mut ::shred::World) { + fn setup(world: &mut shred::World) { #( - <#tys as ::shred::SystemData> :: setup(world); + <#tys as shred::SystemData> :: setup(world); )* } - fn fetch(world: & #impl_fetch_lt ::shred::World) -> Self { + fn fetch(world: & #impl_fetch_lt shred::World) -> Self { #fetch_return } - fn reads() -> Vec<::shred::ResourceId> { + fn reads() -> Vec { let mut r = Vec::new(); #( { - let mut reads = <#tys as ::shred::SystemData> :: reads(); + let mut reads = <#tys as shred::SystemData> :: reads(); r.append(&mut reads); } )* r } - fn writes() -> Vec<::shred::ResourceId> { + fn writes() -> Vec { let mut r = Vec::new(); #( { - let mut writes = <#tys as ::shred::SystemData> :: writes(); + let mut writes = <#tys as shred::SystemData> :: writes(); r.append(&mut writes); } )* @@ -138,13 +138,13 @@ fn gen_from_body(ast: &Data, name: &Ident) -> (proc_macro2::TokenStream, Vec { let count = tys.len(); - let fetch = vec![quote! { ::shred::SystemData::fetch(world) }; count]; + let fetch = vec![quote! { shred::SystemData::fetch(world) }; count]; quote! { #name ( #( #fetch ),* ) From 4a7216013abdf0165699922b55b9dedafa3908fe Mon Sep 17 00:00:00 2001 From: Isse Date: Tue, 21 Nov 2023 23:07:46 +0100 Subject: [PATCH 3/5] revert unintended changes --- examples/thread_local.rs | 2 +- src/system.rs | 18 ------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/examples/thread_local.rs b/examples/thread_local.rs index c2e3dbcc..51b231bd 100644 --- a/examples/thread_local.rs +++ b/examples/thread_local.rs @@ -1,4 +1,4 @@ -use shred::{DispatcherBuilder, Read, System, SystemData, World, Write}; +use shred::{DispatcherBuilder, Read, ResourceId, System, SystemData, World, Write}; #[derive(Debug, Default)] struct ResA; diff --git a/src/system.rs b/src/system.rs index e4d77e86..dca8c78e 100644 --- a/src/system.rs +++ b/src/system.rs @@ -284,11 +284,6 @@ pub trait SystemData<'a> { /// /// Please note that returning wrong dependencies can lead to a panic. fn writes() -> Vec; - - /// Returns names of retrieved resources. - fn resource_names() -> Vec<&'static str> { - vec![std::any::type_name::()] - } } impl<'a, T> DynamicSystemData<'a> for T @@ -436,19 +431,6 @@ macro_rules! impl_data { r } - - fn resource_names() -> Vec<&'static str> { - #![allow(unused_mut)] - - let mut r = Vec::new(); - - $( { - let mut names = <$ty as SystemData>::resource_names(); - r.append(&mut names); - } )* - - r - } } }; } From 99df7090e90aa698926a95a3bed708b5b5d1acdd Mon Sep 17 00:00:00 2001 From: Isse Date: Wed, 22 Nov 2023 00:58:50 +0100 Subject: [PATCH 4/5] add missed path --- shred-derive/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shred-derive/src/lib.rs b/shred-derive/src/lib.rs index 0b3f3c65..757eb8d9 100644 --- a/shred-derive/src/lib.rs +++ b/shred-derive/src/lib.rs @@ -107,7 +107,7 @@ fn gen_identifiers(fields: &Punctuated) -> Vec { /// 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); } } From 45cd2f1fa2fc0474d2f313bf0318d9cec8600ec6 Mon Sep 17 00:00:00 2001 From: Isse Date: Sun, 26 Nov 2023 16:00:12 +0100 Subject: [PATCH 5/5] fix examples and tests without default features --- examples/derive_bundle.rs | 2 ++ examples/seq_dispatch.rs | 2 ++ tests/dispatch.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/examples/derive_bundle.rs b/examples/derive_bundle.rs index fb4e6ac9..b16a15dc 100644 --- a/examples/derive_bundle.rs +++ b/examples/derive_bundle.rs @@ -1,3 +1,5 @@ +#[cfg(not(feature = "shred-derive"))] +use shred::ResourceId; use shred::{Read, SystemData, World, Write}; #[derive(Debug, Default)] diff --git a/examples/seq_dispatch.rs b/examples/seq_dispatch.rs index ec2cd563..a07eecdd 100644 --- a/examples/seq_dispatch.rs +++ b/examples/seq_dispatch.rs @@ -1,3 +1,5 @@ +#[cfg(not(feature = "shred-derive"))] +use shred::ResourceId; use shred::{DispatcherBuilder, Read, System, SystemData, World, Write}; #[derive(Debug, Default)] diff --git a/tests/dispatch.rs b/tests/dispatch.rs index 1e0e1d54..02741b7a 100644 --- a/tests/dispatch.rs +++ b/tests/dispatch.rs @@ -1,3 +1,5 @@ +#[cfg(not(feature = "shred-derive"))] +use shred::ResourceId; use shred::{Dispatcher, DispatcherBuilder, Read, RunningTime, System, SystemData, World, Write}; fn sleep_short() {