summaryrefslogtreecommitdiff
path: root/ecs-macros/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-06-07 18:50:46 +0200
committerHampusM <hampus@hampusmat.com>2025-06-07 18:50:46 +0200
commit193781bd87b78fae840e6ff854f5b93b8db42195 (patch)
tree6f87fec47dd22d523c5f2b23f8e612f1f9cde09c /ecs-macros/src/lib.rs
parent11367ae5b43771b722e2f98b3f3edaef1fb4505f (diff)
refactor(ecs): remove Component Handle & HandleMut assoc types
Diffstat (limited to 'ecs-macros/src/lib.rs')
-rw-r--r--ecs-macros/src/lib.rs72
1 files changed, 1 insertions, 71 deletions
diff --git a/ecs-macros/src/lib.rs b/ecs-macros/src/lib.rs
index aab8dd2..7d00736 100644
--- a/ecs-macros/src/lib.rs
+++ b/ecs-macros/src/lib.rs
@@ -14,7 +14,6 @@ use syn::{
ItemStruct,
ItemUnion,
Path,
- Type,
};
use toml::value::{Table as TomlTable, Value as TomlValue};
@@ -49,15 +48,11 @@ macro_rules! syn_path_segment {
/// - Not attributed to a type item
/// - The attributed-to type item is generic
/// - If parsing the user crate's `Cargo.toml` file fails.
-#[proc_macro_derive(Component, attributes(component))]
+#[proc_macro_derive(Component)]
pub fn component_derive(input: TokenStream) -> TokenStream
{
let item: TypeItem = parse::<Item>(input).unwrap().try_into().unwrap();
- let ComponentAttribute { handle_type, handle_mut_type } = item
- .attribute::<ComponentAttribute>("component")
- .unwrap_or_default();
-
let item_ident = item.ident();
let (impl_generics, type_generics, where_clause) = item.generics().split_for_impl();
@@ -88,10 +83,6 @@ pub fn component_derive(input: TokenStream) -> TokenStream
use ::std::sync::{LazyLock, Mutex};
use #ecs_path::component::Component;
- use #ecs_path::component::{
- Handle as ComponentHandle,
- HandleMut as ComponentHandleMut
- };
use #ecs_path::uid::{Uid, Kind as UidKind};
use #ecs_path::system::Input as SystemInput;
@@ -102,9 +93,6 @@ pub fn component_derive(input: TokenStream) -> TokenStream
impl #impl_generics Component for #item_ident #type_generics
#where_clause
{
- type HandleMut<'component> = #handle_mut_type;
- type Handle<'component> = #handle_type;
-
fn id() -> Uid
{
*#id_var_ident
@@ -326,61 +314,3 @@ fn find_engine_ecs_crate_path() -> Option<Path>
None
})
}
-
-#[derive(Debug)]
-struct ComponentAttribute
-{
- handle_type: proc_macro2::TokenStream,
- handle_mut_type: proc_macro2::TokenStream,
-}
-
-impl FromAttribute for ComponentAttribute
-{
- fn from_attribute(attribute: &Attribute) -> Result<Self, syn::Error>
- {
- let mut handle_type: Option<Type> = None;
- let mut handle_mut_type: Option<Type> = None;
-
- attribute.parse_nested_meta(|meta| {
- let Some(flag) = meta.path.get_ident() else {
- return Err(meta.error("Not a single identifier"));
- };
-
- if flag == "handle_type" {
- let value = meta.value()?;
-
- handle_type = Some(value.parse::<Type>()?);
-
- return Ok(());
- } else if flag == "handle_mut_type" {
- let value = meta.value()?;
-
- handle_mut_type = Some(value.parse::<Type>()?);
-
- return Ok(());
- }
-
- Err(meta.error("Unrecognized token"))
- })?;
-
- Ok(Self {
- handle_type: handle_type
- .map_or_else(|| Self::default().handle_type, ToTokens::into_token_stream),
- handle_mut_type: handle_mut_type.map_or_else(
- || Self::default().handle_mut_type,
- ToTokens::into_token_stream,
- ),
- })
- }
-}
-
-impl Default for ComponentAttribute
-{
- fn default() -> Self
- {
- Self {
- handle_type: quote! { ComponentHandle<'component, Self> },
- handle_mut_type: quote! { ComponentHandleMut<'component, Self> },
- }
- }
-}