Skip to content

Commit 0c92aff

Browse files
committed
fix: code for syn v2
1 parent 6eaa193 commit 0c92aff

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

eventually-macros/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ keywords = ["architecture", "ddd", "event-sourcing", "cqrs", "es"]
2020
proc-macro = true
2121

2222
[dependencies]
23-
syn = { version = "2.0.0", features = ["full"] }
24-
quote = "1.0.35"
23+
syn = { version = "2.0.100", features = ["full"] }
24+
quote = "1.0.40"
2525
eventually = { path = "../eventually" }

eventually-macros/src/lib.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
use proc_macro::TokenStream;
88
use quote::quote;
9-
use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta, Path};
9+
use syn::punctuated::Punctuated;
10+
use syn::{parse_macro_input, Fields, ItemStruct, Token, Type};
1011

1112
/// Implements a newtype to use the [`eventually::aggregate::Root`] instance with
1213
/// user-defined [`eventually::aggregate::Aggregate`] types.
@@ -22,7 +23,7 @@ use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta
2223
/// being an example of user-defined `Aggregate` type) outside the `eventually` crate (E0116).
2324
/// Therefore, a newtype that uses `aggregate::Root<T>` is required.
2425
///
25-
/// This attribute macro makes the implementation of a newtype easy, as it Implements
26+
/// This attribute macro makes the implementation of a newtype easy, as it implements
2627
/// conversion traits from and to `aggregate::Root<T>` and implements automatic deref
2728
/// through [`std::ops::Deref`] and [`std::ops::DerefMut`].
2829
///
@@ -31,19 +32,14 @@ use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta
3132
/// This method will panic if the Aggregate Root type is not provided as a macro parameter.
3233
#[proc_macro_attribute]
3334
pub fn aggregate_root(args: TokenStream, item: TokenStream) -> TokenStream {
34-
let args = parse_macro_input!(args as AttributeArgs);
3535
let mut item = parse_macro_input!(item as ItemStruct);
3636
let item_ident = item.ident.clone();
3737

38-
let aggregate_type = args
39-
.first()
40-
.and_then(|meta| match meta {
41-
NestedMeta::Meta(Meta::Path(Path { segments, .. })) => Some(segments),
42-
_ => None,
43-
})
44-
.and_then(|segments| segments.first())
45-
.map(|segment| segment.ident.clone())
46-
.expect("the aggregate root type must be provided as macro parameter");
38+
let aggregate_type: Type =
39+
parse_macro_input!(args with Punctuated::<Type, Token![,]>::parse_terminated)
40+
.into_iter()
41+
.next()
42+
.expect("the aggregate root type must be provided as macro parameter");
4743

4844
item.fields = Fields::Unnamed(
4945
syn::parse2(quote! { (eventually::aggregate::Root<#aggregate_type>) }).unwrap(),

eventually-postgres/tests/aggregate_repository.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async fn it_works() {
1919
.await
2020
.unwrap();
2121

22-
let aggregate_id = setup::TestAggregateId(rand::thread_rng().gen::<i64>());
22+
let aggregate_id = setup::TestAggregateId(rand::rng().random::<i64>());
2323

2424
let result = aggregate_repository
2525
.get(&aggregate_id)
@@ -68,7 +68,7 @@ async fn it_detects_data_races_and_returns_conflict_error() {
6868
.await
6969
.unwrap();
7070

71-
let aggregate_id = setup::TestAggregateId(rand::thread_rng().gen::<i64>());
71+
let aggregate_id = setup::TestAggregateId(rand::rng().random::<i64>());
7272

7373
let mut root = setup::TestAggregateRoot::create(aggregate_id, "John Dee".to_owned())
7474
.expect("aggregate root should be created");

eventually-postgres/tests/event_store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async fn append_with_no_version_check_works() {
2020
.await
2121
.unwrap();
2222

23-
let id = rand::thread_rng().gen::<i64>();
23+
let id = rand::rng().random::<i64>();
2424
let event_stream_id = format!("test-event-stream-{}", id);
2525

2626
let expected_events = vec![setup::TestDomainEvent::WasCreated {
@@ -76,7 +76,7 @@ async fn it_works_with_version_check_for_conflict() {
7676
.await
7777
.unwrap();
7878

79-
let id = rand::thread_rng().gen::<i64>();
79+
let id = rand::rng().random::<i64>();
8080
let event_stream_id = format!("test-event-stream-{}", id);
8181

8282
let expected_events = vec![setup::TestDomainEvent::WasCreated {
@@ -151,7 +151,7 @@ async fn it_handles_concurrent_writes_to_the_same_stream() {
151151
.await
152152
.unwrap();
153153

154-
let id = rand::thread_rng().gen::<i64>();
154+
let id = rand::rng().random::<i64>();
155155
let event_stream_id = format!("test-event-stream-{}", id);
156156

157157
let expected_events = vec![setup::TestDomainEvent::WasCreated {

examples/bank-accounting/src/domain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl aggregate::Aggregate for BankAccount {
112112

113113
fn apply(state: Option<Self>, event: Self::Event) -> Result<Self, Self::Error> {
114114
match state {
115-
None => match event {
115+
Option::None => match event {
116116
BankAccountEvent::WasOpened {
117117
id,
118118
initial_balance,

0 commit comments

Comments
 (0)