Choosing Between Two Rust Struct/Enum Designs

Hi,

I'm currently working on a project and have reached a point where I need to decide between two design approaches for representing trial info in my application.

The software may have a different trial period based on whether it is the beta version or not. Below are the two approaches that come to my mind, currently, I'm leaning towards the former, but I couldn't give a strong reason to argue this. So, I'm seeking help from the community. Any suggestions for these two approaches, or are there any better alternatives? Thanks.

The first approach:

struct TrialInfo {
  start_time: String,
  end_time: String,
  days_left: usize,
}

enum Trial {
  Beta(TrialInfo),
  Stable(TrialInfo),
}

And the second approach:

enum TrialKind {
    Beta,
    Stable,
}

struct TrialInfo {
    kind: TrialKind,
    start_time: String,
    end_time: String,
    days_left: usize,
}

I prefer the second because TrialKind is really as simple as an integer.

You have to consider how to match against the enum carrying data: Generic referencing enum inner data

6 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.