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

refactor: replace actors framework events boilerplate code with macros #237

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

links234
Copy link
Contributor

@links234 links234 commented Oct 28, 2024

Refactor the actors framework repeatable code into a macro to reduce boilerplate code when defining EventBus.

  • Define EventBus Macro:

    • Add define_event_bus macro in client/actors-framework/src/event_bus.rs to automate the definition and implementation of EventBus and ProvidesEventBus traits for different event types.
    • Replace existing EventBus and ProvidesEventBus trait implementations with the define_event_bus macro in client/blockchain-service/src/events.rs and client/file-transfer-service/src/events.rs.
  • Derive Macro for EventBusMessage:

    • Add a new derive macro EventBusMessage in client/actors-framework/src/event_bus.rs to automate the implementation of EventBusMessage trait for different event types.
    • Create a new crate actors-framework-macro and implement the derive macro EventBusMessage in client/actors-framework-macro/src/lib.rs.
    • Use derive(EventBusMessage) for all event types in client/blockchain-service/src/events.rs and client/file-transfer-service/src/events.rs.
    • Delete the lines with impl EventBusMessage for ... in client/blockchain-service/src/events.rs and client/file-transfer-service/src/events.rs.
  • Cargo.toml Updates:

    • Add actors-framework-macro dependency in client/actors-framework/Cargo.toml, client/blockchain-service/Cargo.toml, and client/file-transfer-service/Cargo.toml.
    • Add actors-framework-macro to the workspace in Cargo.toml.

For more details, open the Copilot Workspace session.

Refactor the actors framework repeatable code into a macro to reduce boilerplate code when defining `EventBus`.

* **Define EventBus Macro:**
  - Add `define_event_bus` macro in `client/actors-framework/src/event_bus.rs` to automate the definition and implementation of `EventBus` and `ProvidesEventBus` traits for different event types.
  - Replace existing `EventBus` and `ProvidesEventBus` trait implementations with the `define_event_bus` macro in `client/blockchain-service/src/events.rs` and `client/file-transfer-service/src/events.rs`.

* **Derive Macro for EventBusMessage:**
  - Add a new derive macro `EventBusMessage` in `client/actors-framework/src/event_bus.rs` to automate the implementation of `EventBusMessage` trait for different event types.
  - Create a new crate `actors-framework-macro` and implement the derive macro `EventBusMessage` in `client/actors-framework-macro/src/lib.rs`.
  - Use `derive(EventBusMessage)` for all event types in `client/blockchain-service/src/events.rs` and `client/file-transfer-service/src/events.rs`.
  - Delete the lines with `impl EventBusMessage for ...` in `client/blockchain-service/src/events.rs` and `client/file-transfer-service/src/events.rs`.

* **Cargo.toml Updates:**
  - Add `actors-framework-macro` dependency in `client/actors-framework/Cargo.toml`, `client/blockchain-service/Cargo.toml`, and `client/file-transfer-service/Cargo.toml`.
  - Add `actors-framework-macro` to the workspace in `Cargo.toml`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Moonsong-Labs/storage-hub?shareId=XXXX-XXXX-XXXX-XXXX).
@links234 links234 changed the title Refactor actors framework to replace boilerplate code with macros refactor: replace actors framework events boilerplate code with macros Oct 30, 2024
@links234 links234 marked this pull request as draft October 30, 2024 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant