Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Events Handling (#1) #2

Merged
merged 42 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6697475
Basic project structure with Event and VersionedEvent impls
ilslv Aug 13, 2021
a6e1847
Add Makefile, GitHub Actions, PR and Issue templates
ilslv Aug 13, 2021
238058d
Add EventInitialized, EventSourced and InitialEvent
ilslv Aug 13, 2021
83f9911
Fix CI
ilslv Aug 13, 2021
f31ca0c
Finally check uniqueness of event_type() and ver() at compile-time!
ilslv Aug 16, 2021
42c5b4d
Add docs explaining unique checks macro shenanigans [skip ci]
ilslv Aug 16, 2021
7dfe985
Add ability to skip uniqueness check for event_type and ver for Event…
ilslv Aug 17, 2021
7df18ef
Add more tests
ilslv Aug 17, 2021
d454eaf
Final touches
ilslv Aug 17, 2021
c61e8bb
Use nightly toolchain on CI
ilslv Aug 17, 2021
32aec5d
Fix CI
ilslv Aug 17, 2021
aa8f2b4
Remove stable and beta toolchains in testing
ilslv Aug 17, 2021
e815e60
CHANGELOG
ilslv Aug 17, 2021
11107d1
Merge branch 'master' into 1-event-sourcing
tyranron Aug 17, 2021
b048ca1
Introduce EventName and EventVersion and support them in proc-macros
ilslv Aug 17, 2021
c6f1ff9
CHANGELOG
ilslv Aug 17, 2021
d7647b6
Merge branch 'master' into 1-event-sourcing
ilslv Aug 17, 2021
c477378
Some corrections [skip ci]
tyranron Aug 17, 2021
5166708
Merge remote-tracking branch 'origin/1-event-sourcing' into 1-event-s…
tyranron Aug 17, 2021
4bd1c85
Replace event_type() with name() everywhere [skip ci]
ilslv Aug 17, 2021
8bc5e8c
Add es feature-gates [skip ci]
ilslv Aug 17, 2021
418b233
Split derive and es feature-gates [skip ci]
ilslv Aug 17, 2021
683456b
Use arcana-core crate for arcana-codegen-impl docs [skip ci]
ilslv Aug 17, 2021
7a8ceb5
WIP [skip ci]
ilslv Aug 17, 2021
8a9b4ec
Cover Event derive macro with docs [skip ci]
ilslv Aug 17, 2021
32f233f
Cover VersionedEvent derive macro with docs [skip ci]
ilslv Aug 17, 2021
18a0c1a
Move events uniqueness check to arcana_codegen crate [skip ci]
ilslv Aug 18, 2021
de5edea
Use only required number of events in uniqueness check [skip ci]
ilslv Aug 20, 2021
fb0260a
Add arcana-codegen-shim [skip ci]
ilslv Aug 20, 2021
d74ae8e
Add MSRV check
ilslv Aug 23, 2021
eff3a0a
Fix CI
ilslv Aug 23, 2021
373d0c1
Remove safety_guard dependency
ilslv Aug 23, 2021
4ad217b
Some corrections [skip ci]
tyranron Aug 24, 2021
088db1a
Corrections
ilslv Aug 25, 2021
8cea01b
Correction
ilslv Aug 25, 2021
0a40645
Disable -Z minimal-versions for now on CI MSRV check
ilslv Aug 25, 2021
8a84f85
Some corrections [skip ci]
tyranron Aug 25, 2021
23306f4
Merge remote-tracking branch 'origin/1-event-sourcing' into 1-event-s…
tyranron Aug 25, 2021
2d2c92d
Try to support generics in internal uniqueness glue code
ilslv Aug 26, 2021
843cae5
Hide docs dependencies behind the feature
ilslv Aug 26, 2021
7685c03
Corrections
ilslv Aug 26, 2021
f522fcf
Corrections
tyranron Aug 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ version = "0.1.0"
edition = "2018"

[features]
default = ["derive"]
default = ["derive", "es"]
derive = []
es = ["arcana-core/es"]

[dependencies]
arcana-core = { version = "0.1.0", path = "./core" }
Expand Down
1 change: 1 addition & 0 deletions codegen/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
proc-macro = true

[dependencies]
arcana-core = { version = "0.1.0", path = "../../core" }
proc-macro2 = "1.0"
quote = "1.0"
strum = { version = "0.21", features = ["derive"] }
Expand Down
66 changes: 35 additions & 31 deletions codegen/impl/src/event/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Definition of `arcana::Event` derive macro for enums.
//! Definition of [`Event`] derive macro for enums.
//!
//! [`Event`]: arcana_core::Event

pub(crate) mod versioned;

Expand All @@ -15,7 +17,9 @@ use synthez::{ParseAttrs, ToTokens};

const MAX_UNIQUE_EVENTS: usize = 100_000;

/// Derives `arcana::Event` for enum.
/// Derives [`Event`] for enum.
///
/// [`Event`]: arcana_core::Event
pub(crate) fn derive(input: TokenStream) -> syn::Result<TokenStream> {
let input: syn::DeriveInput = syn::parse2(input)?;
let definitions = Definitions::try_from(input)?;
Expand All @@ -24,7 +28,7 @@ pub(crate) fn derive(input: TokenStream) -> syn::Result<TokenStream> {
}

#[derive(ToTokens)]
#[to_tokens(append(impl_from, unique_event_type_and_ver))]
#[to_tokens(append(impl_from, unique_event_name_and_ver))]
struct Definitions {
ident: syn::Ident,
generics: syn::Generics,
Expand All @@ -37,7 +41,7 @@ impl Definitions {
let name = &self.ident;
let (impl_generics, ty_generics, where_clause) =
self.generics.split_for_impl();
let (event_types, event_versions): (TokenStream, TokenStream) = self
let (event_names, event_versions): (TokenStream, TokenStream) = self
.variants
.iter()
.map(|(variant, _)| {
Expand Down Expand Up @@ -66,7 +70,7 @@ impl Definitions {
};

(
generate_variant(quote! { event_type }),
generate_variant(quote! { name }),
generate_variant(quote! { ver }),
)
})
Expand All @@ -78,9 +82,9 @@ impl Definitions {
#name #ty_generics #where_clause
{
#[inline(always)]
fn event_type(&self) -> ::arcana::EventName {
fn name(&self) -> ::arcana::EventName {
match self {
#event_types
#event_names
}
}

Expand All @@ -94,8 +98,8 @@ impl Definitions {
}
}

fn unique_event_type_and_ver(&self) -> TokenStream {
if self.attrs.skip_check_unique_type_and_ver() {
fn unique_event_name_and_ver(&self) -> TokenStream {
if self.attrs.skip_check_unique_name_and_ver() {
return TokenStream::new();
}

Expand All @@ -107,7 +111,7 @@ impl Definitions {
.variants
.iter()
.filter_map(|(variant, attr)| {
(!attr.skip_check_unique_type_and_ver()).then(|| {
(!attr.skip_check_unique_name_and_ver()).then(|| {
let ty = &variant.fields.iter().next().unwrap().ty;
quote! { #ty, }
})
Expand All @@ -116,12 +120,12 @@ impl Definitions {

quote! {
impl #impl_generics #name #ty_generics #where_clause {
::arcana::unique_event_type_and_ver_for_enum!(
::arcana::unique_event_name_and_ver_for_enum!(
#max, #event_variants
);
}

::arcana::unique_event_type_and_ver_check!(#name);
::arcana::unique_event_name_and_ver_check!(#name);
}
}
}
Expand Down Expand Up @@ -174,10 +178,10 @@ struct Attrs {
}

impl Attrs {
fn skip_check_unique_type_and_ver(&self) -> bool {
fn skip_check_unique_name_and_ver(&self) -> bool {
matches!(
self.skip.as_ref().map(|sp| sp.item),
Some(SkipAttr::CheckUniqueTypeAndVer),
Some(SkipAttr::CheckUniqueNameAndVer),
)
}
}
Expand All @@ -197,7 +201,7 @@ impl<T> Spanned for Spanning<T> {
#[derive(Clone, Copy, Debug, EnumString, EnumVariantNames)]
#[strum(serialize_all = "snake_case")]
enum SkipAttr {
CheckUniqueTypeAndVer,
CheckUniqueNameAndVer,
}

impl Parse for Spanning<SkipAttr> {
Expand Down Expand Up @@ -237,13 +241,13 @@ mod spec {
#[automatically_derived]
impl ::arcana::Event for Event {
#[inline(always)]
fn event_type(&self) -> ::arcana::EventName {
fn name(&self) -> ::arcana::EventName {
match self {
Self::Event1(inner) => {
::arcana::Event::event_type(inner)
::arcana::Event::name(inner)
}
Self::Event2 { event } => {
::arcana::Event::event_type(event)
::arcana::Event::name(event)
}
}
}
Expand All @@ -262,12 +266,12 @@ mod spec {
}

impl Event {
::arcana::unique_event_type_and_ver_for_enum!(
::arcana::unique_event_name_and_ver_for_enum!(
100000usize, EventUnnamend, EventNamed,
);
}

::arcana::unique_event_type_and_ver_check!(Event);
::arcana::unique_event_name_and_ver_check!(Event);
};

assert_eq!(derive(input).unwrap().to_string(), output.to_string());
Expand All @@ -276,7 +280,7 @@ mod spec {
#[test]
fn skip_unique_check_on_container() {
let input = syn::parse_quote! {
#[event(skip(check_unique_type_and_ver))]
#[event(skip(check_unique_name_and_ver))]
enum Event {
Event1(EventUnnamend),
Event2 {
Expand All @@ -289,13 +293,13 @@ mod spec {
#[automatically_derived]
impl ::arcana::Event for Event {
#[inline(always)]
fn event_type(&self) -> ::arcana::EventName {
fn name(&self) -> ::arcana::EventName {
match self {
Self::Event1(inner) => {
::arcana::Event::event_type(inner)
::arcana::Event::name(inner)
}
Self::Event2 { event } => {
::arcana::Event::event_type(event)
::arcana::Event::name(event)
}
}
}
Expand All @@ -321,7 +325,7 @@ mod spec {
fn skip_unique_check_on_variant() {
let input = syn::parse_quote! {
enum Event {
#[event(skip(check_unique_type_and_ver))]
#[event(skip(check_unique_name_and_ver))]
Event1(EventUnnamend),
Event2 {
event: EventNamed,
Expand All @@ -333,13 +337,13 @@ mod spec {
#[automatically_derived]
impl ::arcana::Event for Event {
#[inline(always)]
fn event_type(&self) -> ::arcana::EventName {
fn name(&self) -> ::arcana::EventName {
match self {
Self::Event1(inner) => {
::arcana::Event::event_type(inner)
::arcana::Event::name(inner)
}
Self::Event2 { event } => {
::arcana::Event::event_type(event)
::arcana::Event::name(event)
}
}
}
Expand All @@ -358,12 +362,12 @@ mod spec {
}

impl Event {
::arcana::unique_event_type_and_ver_for_enum!(
::arcana::unique_event_name_and_ver_for_enum!(
100000usize, EventNamed,
);
}

::arcana::unique_event_type_and_ver_check!(Event);
::arcana::unique_event_name_and_ver_check!(Event);
};

assert_eq!(derive(input).unwrap().to_string(), output.to_string());
Expand Down Expand Up @@ -402,7 +406,7 @@ mod spec {

assert_eq!(
format!("{}", error),
"Unknown value. Allowed values: check_unique_type_and_ver",
"Unknown value. Allowed values: check_unique_name_and_ver",
);
}

Expand Down
Loading