diff options
Diffstat (limited to 'ecs-macros/src/lib.rs')
-rw-r--r-- | ecs-macros/src/lib.rs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/ecs-macros/src/lib.rs b/ecs-macros/src/lib.rs index a6fdf28..aab8dd2 100644 --- a/ecs-macros/src/lib.rs +++ b/ecs-macros/src/lib.rs @@ -1,3 +1,4 @@ +#![deny(clippy::all, clippy::pedantic)] use std::path::PathBuf as FsPathBuf; use proc_macro::TokenStream; @@ -41,6 +42,13 @@ macro_rules! syn_path_segment { }; } +/// Generates a `Component` implementation. +/// +/// # Panics +/// Will panic if: +/// - 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))] pub fn component_derive(input: TokenStream) -> TokenStream { @@ -117,6 +125,11 @@ pub fn component_derive(input: TokenStream) -> TokenStream .into() } +/// Generates a `Sole` implementation. +/// +/// # Panics +/// Will panic if not attributed to a type item or if parsing the user crate's +/// `Cargo.toml` file fails. #[proc_macro_derive(Sole, attributes(sole))] pub fn sole_derive(input: TokenStream) -> TokenStream { @@ -189,9 +202,7 @@ impl TypeItem let mut attr: Option<&Attribute> = None; for item_attr in item_attrs { - if attr.is_some() { - panic!("Expected only one {} attribute", attr_ident); - } + assert!(attr.is_none(), "Expected only one {attr_ident} attribute"); if item_attr.path().get_ident()? == attr_ident { attr = Some(item_attr); @@ -354,11 +365,11 @@ impl FromAttribute for ComponentAttribute Ok(Self { handle_type: handle_type - .map(|handle_type| handle_type.into_token_stream()) - .unwrap_or_else(|| Self::default().handle_type), - handle_mut_type: handle_mut_type - .map(|handle_mut_type| handle_mut_type.into_token_stream()) - .unwrap_or_else(|| Self::default().handle_mut_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, + ), }) } } |