From c5d1cdd23de16b4eec9fb59dc0ed8358172acec7 Mon Sep 17 00:00:00 2001 From: "Claas j. Gramann" Date: Tue, 23 Apr 2024 01:16:33 +0200 Subject: [PATCH 1/3] Fix #773 --- specs-derive/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/specs-derive/src/lib.rs b/specs-derive/src/lib.rs index 5a73e83f7..9ac5c0b51 100644 --- a/specs-derive/src/lib.rs +++ b/specs-derive/src/lib.rs @@ -15,7 +15,7 @@ extern crate syn; use proc_macro::TokenStream; use syn::{ parse::{Parse, ParseStream, Result}, - DeriveInput, Path, + DeriveInput, Path, PathArguments, }; mod impl_saveload; @@ -68,9 +68,14 @@ fn impl_component(ast: &DeriveInput) -> proc_macro2::TokenStream { }) .unwrap_or_else(|| parse_quote!(DenseVecStorage)); + let additional_generics = match storage.segments.last().unwrap().arguments { + PathArguments::AngleBracketed(_) => quote!(), + _ => quote!(), + }; + quote! { impl #impl_generics Component for #name #ty_generics #where_clause { - type Storage = #storage; + type Storage = #storage #additional_generics; } } } From 2cefae15729bb7bd1bcc79e857efcd5c6db5b3c3 Mon Sep 17 00:00:00 2001 From: "Claas j. Gramann" Date: Tue, 23 Apr 2024 08:23:45 +0200 Subject: [PATCH 2/3] Add example for #733 --- docs/tutorials/src/02_hello_world.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/tutorials/src/02_hello_world.md b/docs/tutorials/src/02_hello_world.md index d27864d12..90a776d02 100644 --- a/docs/tutorials/src/02_hello_world.md +++ b/docs/tutorials/src/02_hello_world.md @@ -84,10 +84,25 @@ struct Velocity { If the `#[storage(...)]` attribute is omitted, the given component will be stored in a `DenseVecStorage` by default. But for this example, we are explicitly asking for these components to be kept in a `VecStorage` instead (see -the later [storages chapter][sc] for more details). But before we move on, we +the later [storages chapter][sc] for more details). + +`#[storage(VecStorage)]` assumes `` as the default type parameter for the storage. +More complex type parameters can be specified explicitly: + +```rust,ignore +#[derive(Component, Debug)] +#[storage(FlaggedStorage>)] +pub struct Data { + [..] +} +``` +(see the later [`FlaggedStorage` and modification events chapter][tc] for more details on `FlaggedStorage`) + +But before we move on, we need to create a world in which to store all of our components. [sc]: ./05_storages.html +[tc]: ./12_tracked.html ## The `World` From 0fc05525576bb3778ca1b62e28a615fa5ab88050 Mon Sep 17 00:00:00 2001 From: "Claas j. Gramann" Date: Tue, 23 Apr 2024 09:46:44 +0200 Subject: [PATCH 3/3] Add doc example for default type parameters --- specs-derive/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/specs-derive/src/lib.rs b/specs-derive/src/lib.rs index 9ac5c0b51..139f4c9ee 100644 --- a/specs-derive/src/lib.rs +++ b/specs-derive/src/lib.rs @@ -28,7 +28,17 @@ mod impl_saveload; /// use specs::storage::VecStorage; /// /// #[derive(Component, Debug)] -/// #[storage(VecStorage)] // This line is optional, defaults to `DenseVecStorage` +/// #[storage(VecStorage)] // This line is optional, defaults to `DenseVecStorage` +/// struct Pos(f32, f32, f32); +/// ``` +/// +/// When the type parameter is `` it can be omitted i.e.: +/// +///```rust,ignore +/// use specs::storage::VecStorage; +/// +/// #[derive(Component, Debug)] +/// #[storage(VecStorage)] // Equals to #[storage(VecStorage)] /// struct Pos(f32, f32, f32); /// ``` #[proc_macro_derive(Component, attributes(storage))]