Skip to content

Commit

Permalink
feat!: make setup macros more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
mhatzl committed Jun 23, 2023
1 parent e052054 commit 1558b45
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "evident"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
description = "Pub/Sub library using IDs to identify events."
repository = "https://github.com/mhatzl/evident"
Expand Down
92 changes: 51 additions & 41 deletions src/creation_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
/// ```ignore
/// evident::create_static_publisher!(
/// <visibility specifier> <Name for the publisher>,
/// <Struct implementing `evident::publisher::Id`>,
/// <Struct implementing `evident::event::entry::EventEntry`>,
/// <Struct implementing `evident::event::intermediary::IntermediaryEvent`>,
/// id_type = <Struct implementing `evident::publisher::Id`>,
/// entry_type = <Struct implementing `evident::event::entry::EventEntry`>,
/// interm_event_type = <Struct implementing `evident::event::intermediary::IntermediaryEvent`>,
/// filter_type = <Optional Struct implementing `evident::event::filter::Filter`>,
/// filter = <Optional instance of the filter. Must be set if filter type is set>,
/// CAPTURE_CHANNEL_BOUND = <`usize` literal for the channel bound used to capture events>,
/// SUBSCRIPTION_CHANNEL_BOUND = <`usize` literal for the channel bound used per subscription>,
/// capture_channel_bound = <`usize` literal for the channel bound used to capture events>,
/// subscription_channel_bound = <`usize` literal for the channel bound used per subscription>,
/// non_blocking = <`bool` literal defining if event finalizing should be non-blocking (`true`), or block the thread (`false`)>
/// );
/// ```
Expand All @@ -24,11 +24,11 @@
/// ```ignore
/// evident::create_static_publisher!(
/// pub MY_PUBLISHER,
/// MyId,
/// MyEventEntry,
/// MyIntermEvent,
/// CAPTURE_CHANNEL_BOUND = 100,
/// SUBSCRIPTION_CHANNEL_BOUND = 50,
/// id_type = MyId,
/// entry_type = MyEventEntry,
/// interm_event_type = MyIntermEvent,
/// capture_channel_bound = 100,
/// subscription_channel_bound = 50,
/// non_blocking = true
/// );
/// ```
Expand All @@ -38,27 +38,27 @@
/// ```ignore
/// evident::create_static_publisher!(
/// pub MY_PUBLISHER,
/// MyId,
/// MyEventEntry,
/// MyIntermEvent,
/// id_type = MyId,
/// entry_type = MyEventEntry,
/// interm_event_type = MyIntermEvent,
/// filter_type = MyFilter,
/// filter = MyFilter::default(),
/// CAPTURE_CHANNEL_BOUND = 100,
/// SUBSCRIPTION_CHANNEL_BOUND = 50,
/// capture_channel_bound = 100,
/// subscription_channel_bound = 50,
/// non_blocking = true
/// );
/// ```
///
#[macro_export]
macro_rules! create_static_publisher {
($publisher_name:ident,
$id_t:ty,
$entry_t:ty,
$interm_event_t:ty,
id_type = $id_t:ty,
entry_type = $entry_t:ty,
interm_event_type = $interm_event_t:ty,
$(filter_type=$filter_t:ty,)?
$(filter=$filter:expr,)?
CAPTURE_CHANNEL_BOUND = $cap_channel_bound:expr,
SUBSCRIPTION_CHANNEL_BOUND = $sub_channel_bound:expr,
capture_channel_bound = $cap_channel_bound:expr,
subscription_channel_bound = $sub_channel_bound:expr,
non_blocking = $try_capture:literal
) => {
$crate::z__setup_static_publisher!(
Expand All @@ -74,13 +74,13 @@ macro_rules! create_static_publisher {
);
};
($visibility:vis $publisher_name:ident,
$id_t:ty,
$entry_t:ty,
$interm_event_t:ty,
id_type = $id_t:ty,
entry_type = $entry_t:ty,
interm_event_type = $interm_event_t:ty,
$(filter_type=$filter_t:ty,)?
$(filter=$filter:expr,)?
CAPTURE_CHANNEL_BOUND = $cap_channel_bound:expr,
SUBSCRIPTION_CHANNEL_BOUND = $sub_channel_bound:expr,
capture_channel_bound = $cap_channel_bound:expr,
subscription_channel_bound = $sub_channel_bound:expr,
non_blocking = $try_capture:literal
) => {
$crate::z__setup_static_publisher!(
Expand Down Expand Up @@ -221,33 +221,43 @@ macro_rules! z__create_static_publisher {
/// ## Usage
///
/// In the following example, text between `<>` is used as placeholder.
/// `no_export` may be set at the beginning to prevent `#[macro_export]` from being added.
/// `no_export,` may be set at the beginning to prevent `#[macro_export]` from being added.
///
/// Note: Set fully qualified paths to make the macro accessible from anywhere.
/// Note: Set fully qualified paths for the types to make the macro accessible from anywhere.
///
/// ```ignore
/// evident::create_set_event_macro!(
/// <Struct implementing `evident::publisher::Id`>,
/// <Struct implementing `evident::event::EventEntry`>,
/// <Struct implementing `evident::event::IntermediaryEvent`>
/// id_type = <Struct implementing `evident::publisher::Id`>,
/// entry_type = <Struct implementing `evident::event::EventEntry`>,
/// interm_event_type = <Struct implementing `evident::event::IntermediaryEvent`>
/// );
/// ```
///
/// **Example with dummy implementations:**
///
/// ```ignore
/// evident::create_set_event_macro!(
/// my_crate::my_mod::MyId,
/// my_crate::my_mod::MyEventEntry,
/// my_crate::my_mod::MyInterimEvent
/// id_type = my_crate::my_mod::MyId,
/// entry_type = my_crate::my_mod::MyEventEntry,
/// interm_event_type = my_crate::my_mod::MyInterimEvent
/// );
/// ```
///
/// **Example with no export:**
///
/// ```ignore
/// evident::create_set_event_macro!(
/// no_export,
/// id_type = my_crate::my_mod::MyId,
/// entry_type = my_crate::my_mod::MyEventEntry,
/// interm_event_type = my_crate::my_mod::MyInterimEvent
/// );
/// ```
///
#[macro_export]
macro_rules! create_set_event_macro {
($id_t:ty,
$entry_t:ty,
$interm_event_t:ty
(id_type = $id_t:ty,
entry_type = $entry_t:ty,
interm_event_type = $interm_event_t:ty
) => {
#[macro_export]
macro_rules! set_event {
Expand All @@ -266,10 +276,10 @@ macro_rules! create_set_event_macro {
};
}
};
(no_export
$id_t:ty,
$entry_t:ty,
$interm_event_t:ty
(no_export,
id_type = $id_t:ty,
entry_type = $entry_t:ty,
interm_event_type = $interm_event_t:ty
) => {
macro_rules! set_event {
($id:expr) => {
Expand Down
18 changes: 9 additions & 9 deletions tests/min_concretise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ mod interim_event;

evident::create_static_publisher!(
PUBLISHER,
MinId,
MinEventEntry,
MinInterimEvent,
CAPTURE_CHANNEL_BOUND = 1,
SUBSCRIPTION_CHANNEL_BOUND = 1,
id_type = MinId,
entry_type = MinEventEntry,
interm_event_type = MinInterimEvent,
capture_channel_bound = 1,
subscription_channel_bound = 1,
non_blocking = true
);

// Note: **no_export** to prevent the macro from adding `#[macro_export]`.
evident::create_set_event_macro!(
no_export
MinId,
MinEventEntry,
MinInterimEvent
no_export,
id_type = MinId,
entry_type = MinEventEntry,
interm_event_type = MinInterimEvent
);

#[test]
Expand Down
18 changes: 9 additions & 9 deletions tests/min_filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ mod interim_event;

evident::create_static_publisher!(
PUBLISHER,
MinId,
MinEventEntry,
MinInterimEvent,
id_type = MinId,
entry_type = MinEventEntry,
interm_event_type = MinInterimEvent,
filter_type = MinFilter,
filter = MinFilter::default(),
CAPTURE_CHANNEL_BOUND = 1,
SUBSCRIPTION_CHANNEL_BOUND = 1,
capture_channel_bound = 1,
subscription_channel_bound = 1,
non_blocking = true
);

// Note: **no_export** to prevent the macro from adding `#[macro_export]`.
evident::create_set_event_macro!(
no_export
MinId,
MinEventEntry,
MinInterimEvent
no_export,
id_type = MinId,
entry_type = MinEventEntry,
interm_event_type = MinInterimEvent
);

#[test]
Expand Down
18 changes: 9 additions & 9 deletions tests/pub_sub/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ pub mod interim_event;

evident::create_static_publisher!(
pub TESTS_PUBLISHER,
MinId,
MinEventEntry,
MinInterimEvent,
CAPTURE_CHANNEL_BOUND = 500,
SUBSCRIPTION_CHANNEL_BOUND = 500,
id_type = MinId,
entry_type = MinEventEntry,
interm_event_type = MinInterimEvent,
capture_channel_bound = 500,
subscription_channel_bound = 500,
non_blocking = true
);

evident::create_set_event_macro!(
no_export
crate::pub_sub::setup::id::MinId,
crate::pub_sub::setup::entry::MinEventEntry,
crate::pub_sub::setup::interim_event::MinInterimEvent
no_export,
id_type = crate::pub_sub::setup::id::MinId,
entry_type = crate::pub_sub::setup::entry::MinEventEntry,
interm_event_type = crate::pub_sub::setup::interim_event::MinInterimEvent
);
16 changes: 8 additions & 8 deletions tests/public_concretise/public_publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use crate::public_concretise::{entry::MinEventEntry, id::MinId, interim_event::M
// Note: **non_blocking = false** will block on `finalize()` (or implicitly on `drop`) until publisher received the event.
evident::create_static_publisher!(
pub PUB_PUBLISHER,
MinId,
MinEventEntry,
MinInterimEvent,
CAPTURE_CHANNEL_BOUND = 1,
SUBSCRIPTION_CHANNEL_BOUND = 1,
id_type = MinId,
entry_type = MinEventEntry,
interm_event_type = MinInterimEvent,
capture_channel_bound = 1,
subscription_channel_bound = 1,
non_blocking = false
);

// Note: Fully qualified path to access the generated `set_event!()` macro from anywhere.
evident::create_set_event_macro!(
crate::public_concretise::MinId,
crate::public_concretise::entry::MinEventEntry,
crate::public_concretise::interim_event::MinInterimEvent
id_type = crate::public_concretise::MinId,
entry_type = crate::public_concretise::entry::MinEventEntry,
interm_event_type = crate::public_concretise::interim_event::MinInterimEvent
);

0 comments on commit 1558b45

Please sign in to comment.