Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 68b2c94

Browse files
committed
Add helpful error when target is not added in derive macro
1 parent f22378d commit 68b2c94

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Added the `E: EntityEvent` bound to `EventlistenerPlugin<E>`, to move compile errors from adding the plugin, to the event itself.
44
- Fixed a benchmark bug.
5+
- Added helpful error message when `EntityEvent` derive macro fails to find `#[target]`.
56

67
# 0.8.0
78

macros/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_eventlistener_derive"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
edition = "2021"
55
description = "Event listeners and callbacks for bevy"
66
license = "MIT OR Apache-2.0"

macros/src/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ pub fn derive(input: TokenStream) -> TokenStream {
2929
// Get attributes #[..] on each field
3030
for attr in field.attrs.iter() {
3131
// Parse the attribute
32-
match attr.meta {
33-
// Find the duplicated idents
34-
syn::Meta::Path(ref path) if path.get_ident().unwrap() == "target" => {
35-
target = Some(field.ident.clone());
32+
if let syn::Meta::Path(ref path) = attr.meta {
33+
if let Some(ident) = path.get_ident() {
34+
if ident == "target" {
35+
target = Some(field.ident.clone());
36+
}
3637
}
37-
_ => (),
3838
}
3939
}
4040
}
@@ -44,7 +44,9 @@ pub fn derive(input: TokenStream) -> TokenStream {
4444
_ => panic!("Must be a struct"),
4545
}
4646

47-
let target = target.unwrap();
47+
let Some(target) = target else {
48+
panic!("Missing `#[target] attribute. You must annotate the field with the target Entity, or instead manually implement EntityEvent.")
49+
};
4850

4951
let gen = quote! {
5052
impl #impl_generics EntityEvent for #name #ty_generics #where_clause {

0 commit comments

Comments
 (0)