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 strum::Display for all DomainEvents #38

Open
1 task
nanderstabel opened this issue Mar 22, 2024 · 0 comments
Open
1 task

Implement strum::Display for all DomainEvents #38

nanderstabel opened this issue Mar 22, 2024 · 0 comments
Labels
Enhancement New feature or improvement to an existing feature

Comments

@nanderstabel
Copy link
Collaborator

Description

The DomainEvent trait consists on an event_type method which should return the enum variant's name. Currently we implement this like so:

    fn event_type(&self) -> String {
        use ConnectionEvent::*;

        let event_type: &str = match self {
            SIOPv2AuthorizationResponseVerified { .. } => "SIOPv2AuthorizationResponseVerified",
        };
        event_type.to_string()
    }

Where we manually need to add match arms for each enum variant (event) that we want to add.

This is a bit cumbersome so a better solution for this would be to simply derive the strum::Display trait on all enums that implement DomainEvent, i.e.:

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, strum::Display)]
pub enum ConnectionEvent {
    SIOPv2AuthorizationResponseVerified { id_token: String },
}

impl DomainEvent for ConnectionEvent {
    fn event_type(&self) -> String {
        self.to_string()
    }
    ...

Motivation

Using this method is much less error-prone

Resources

n/a

To-do List

  • derive strum::Display for all DomainEvent implementations
@nanderstabel nanderstabel added the Enhancement New feature or improvement to an existing feature label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant