diff --git a/.clippy.toml b/.clippy.toml index a36da7ad..4e450f14 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1,5 +1,4 @@ allowed-duplicate-crates = [ - "syn", "thiserror", "thiserror-impl", # These are all coming from eventually-postgres, quite likely sqlx... diff --git a/eventually-macros/Cargo.toml b/eventually-macros/Cargo.toml index c1a038a6..9464cd56 100644 --- a/eventually-macros/Cargo.toml +++ b/eventually-macros/Cargo.toml @@ -20,6 +20,6 @@ keywords = ["architecture", "ddd", "event-sourcing", "cqrs", "es"] proc-macro = true [dependencies] -syn = { version = "1.0.109", features = ["full"] } -quote = "1.0.35" +syn = { version = "2.0.100", features = ["full"] } +quote = "1.0.40" eventually = { path = "../eventually" } diff --git a/eventually-macros/src/lib.rs b/eventually-macros/src/lib.rs index db6ad603..78c063ae 100644 --- a/eventually-macros/src/lib.rs +++ b/eventually-macros/src/lib.rs @@ -6,7 +6,8 @@ use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta, Path}; +use syn::punctuated::Punctuated; +use syn::{parse_macro_input, Fields, ItemStruct, Token, Type}; /// Implements a newtype to use the [`eventually::aggregate::Root`] instance with /// user-defined [`eventually::aggregate::Aggregate`] types. @@ -22,7 +23,7 @@ use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta /// being an example of user-defined `Aggregate` type) outside the `eventually` crate (E0116). /// Therefore, a newtype that uses `aggregate::Root` is required. /// -/// This attribute macro makes the implementation of a newtype easy, as it Implements +/// This attribute macro makes the implementation of a newtype easy, as it implements /// conversion traits from and to `aggregate::Root` and implements automatic deref /// through [`std::ops::Deref`] and [`std::ops::DerefMut`]. /// @@ -31,19 +32,14 @@ use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta /// This method will panic if the Aggregate Root type is not provided as a macro parameter. #[proc_macro_attribute] pub fn aggregate_root(args: TokenStream, item: TokenStream) -> TokenStream { - let args = parse_macro_input!(args as AttributeArgs); let mut item = parse_macro_input!(item as ItemStruct); let item_ident = item.ident.clone(); - let aggregate_type = args - .first() - .and_then(|meta| match meta { - NestedMeta::Meta(Meta::Path(Path { segments, .. })) => Some(segments), - _ => None, - }) - .and_then(|segments| segments.first()) - .map(|segment| segment.ident.clone()) - .expect("the aggregate root type must be provided as macro parameter"); + let aggregate_type: Type = + parse_macro_input!(args with Punctuated::::parse_terminated) + .into_iter() + .next() + .expect("the aggregate root type must be provided as macro parameter"); item.fields = Fields::Unnamed( syn::parse2(quote! { (eventually::aggregate::Root<#aggregate_type>) }).unwrap(), diff --git a/eventually-postgres/tests/aggregate_repository.rs b/eventually-postgres/tests/aggregate_repository.rs index 06df6173..8a0a328d 100644 --- a/eventually-postgres/tests/aggregate_repository.rs +++ b/eventually-postgres/tests/aggregate_repository.rs @@ -19,7 +19,7 @@ async fn it_works() { .await .unwrap(); - let aggregate_id = setup::TestAggregateId(rand::thread_rng().gen::()); + let aggregate_id = setup::TestAggregateId(rand::rng().random::()); let result = aggregate_repository .get(&aggregate_id) @@ -68,7 +68,7 @@ async fn it_detects_data_races_and_returns_conflict_error() { .await .unwrap(); - let aggregate_id = setup::TestAggregateId(rand::thread_rng().gen::()); + let aggregate_id = setup::TestAggregateId(rand::rng().random::()); let mut root = setup::TestAggregateRoot::create(aggregate_id, "John Dee".to_owned()) .expect("aggregate root should be created"); diff --git a/eventually-postgres/tests/event_store.rs b/eventually-postgres/tests/event_store.rs index 704af90d..04e2ac70 100644 --- a/eventually-postgres/tests/event_store.rs +++ b/eventually-postgres/tests/event_store.rs @@ -20,7 +20,7 @@ async fn append_with_no_version_check_works() { .await .unwrap(); - let id = rand::thread_rng().gen::(); + let id = rand::rng().random::(); let event_stream_id = format!("test-event-stream-{}", id); let expected_events = vec![setup::TestDomainEvent::WasCreated { @@ -76,7 +76,7 @@ async fn it_works_with_version_check_for_conflict() { .await .unwrap(); - let id = rand::thread_rng().gen::(); + let id = rand::rng().random::(); let event_stream_id = format!("test-event-stream-{}", id); let expected_events = vec![setup::TestDomainEvent::WasCreated { @@ -151,7 +151,7 @@ async fn it_handles_concurrent_writes_to_the_same_stream() { .await .unwrap(); - let id = rand::thread_rng().gen::(); + let id = rand::rng().random::(); let event_stream_id = format!("test-event-stream-{}", id); let expected_events = vec![setup::TestDomainEvent::WasCreated { diff --git a/examples/bank-accounting/src/domain.rs b/examples/bank-accounting/src/domain.rs index ec44351c..89528b0c 100644 --- a/examples/bank-accounting/src/domain.rs +++ b/examples/bank-accounting/src/domain.rs @@ -112,7 +112,7 @@ impl aggregate::Aggregate for BankAccount { fn apply(state: Option, event: Self::Event) -> Result { match state { - None => match event { + Option::None => match event { BankAccountEvent::WasOpened { id, initial_balance,