Skip to content

Commit

Permalink
feat: Implement PartialEq and Eq for Response
Browse files Browse the repository at this point in the history
Problem: The `Response` type does not impl `PartialEq` or `Eq`, making
it difficult to perform equality comparisons in unit tests.

Solution: Impl `PartialEq` and `Eq` for the `Response` type when the
associated generic state parameter also impls these traits.

Testing: `cargo test`

Issue: #35
  • Loading branch information
Christian Heussy authored and mdeloof committed Jan 1, 2025
1 parent 28a606c commit f705a84
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions statig/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ pub enum Response<S> {
Transition(S),
}

impl<S> PartialEq for Response<S>
where
S: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Handled, Self::Handled) => true,
(Self::Super, Self::Super) => true,
(Self::Transition(s), Self::Transition(o)) => s == o,
_ => false,
}
}
}

impl<S> Eq for Response<S> where S: Eq {}

impl<S> Debug for Response<S>
where
S: Debug,
Expand Down

0 comments on commit f705a84

Please sign in to comment.