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 service framework #25

Merged
merged 5 commits into from
Jan 7, 2024
Merged

Refactor service framework #25

merged 5 commits into from
Jan 7, 2024

Conversation

Kitt3120
Copy link
Owner

@Kitt3120 Kitt3120 commented Jan 7, 2024

Services can now easily interact with each other

 - Way better handling of mutable/immutable attributes
 - Less Mutexes
 - Better handling of passing references through the service framework's API
 - Reimplement get_service accepting a TypeId as a generic parameter for easier usage
 - Reimplement status_map and status_tree as a result of the above adaptations, resulting in way simpler versions
 - Replace all Mutexes with RwLock
 - Remove status_map method of ServiceManager
 - Services vector in ServiceManager now wraps the Service trait objects in a RwLock to potentially make them available mutably through the public API of ServiceManager
 - Add downcast-rs crate
 - Implement get_service<T> method of ServiceManager

Had to use unsafe Rust for this. Tried it with safe Rust for 3 days and couldn't do it. With unsafe Rust, it's very easy. It's also still kinda safe, as the crash case is checked and prevented before going into the unsafe block.
 - ServiceManager now holds an Arc to itself
 - Self-Arc is now passed to services when initializing them, so they can access other services and copy Arcs to those for themselves
 - Implement SetLock<T> struct which is a wrapper around Option<T> for lazy-initialization
 - ServiceManagerBuilder handles the creation and injection of the Self-Arc of ServiceManager. That's why the build() method is now async and the From trait had to be removed. The From trait cannot be implemented async.
 - To keep everything consistent, the From trait has also been removed from the BotBuilder and the build() method becase async.
 - Adapt Discord service to new service framework and SetLock type
@Kitt3120 Kitt3120 added the feature Adds or requests new feature label Jan 7, 2024
@Kitt3120 Kitt3120 self-assigned this Jan 7, 2024
@Kitt3120 Kitt3120 merged commit 7bad3ad into staging Jan 7, 2024
6 checks passed
@Kitt3120 Kitt3120 deleted the refactor/service-framework branch January 7, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adds or requests new feature
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant