Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Parse "enum-like" fields as string, then implement API for matching it #245

@joao-paulo-parity

Description

@joao-paulo-parity

As discussed in #219, decoding the "enum-like" fields from the API types has some problems

  • Incurs unwarranted parsing errors due to untracked variants
  • Adds extra burden to keep up with the API variants whenever Github decides to change it

#244 suggests a less error-prone interface like the following

enum EventAction {
  Foo
}

struct Event {
  action: String // String instead of EventAction; purposefully private
}

impl Event {
  pub fn is_action(&self, action: EventAction) -> bool {
    self.action == action.to_string()
  }
}

Using [variant].to_string() is less error-prone than working with literal strings since the latter is subject to typos.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions