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

Make Error comparable #127

Merged
merged 1 commit into from
Sep 8, 2023
Merged

Make Error comparable #127

merged 1 commit into from
Sep 8, 2023

Conversation

bytedream
Copy link
Contributor

Description

This PR makes Error comparable. Useful in situations where a custom error enum is used.

This is useful in situation where, for example, a custom error enum is used:

#[derive(Eq, PartialEq, thiserror::Error)]
enum CustomError {
    #[error("error: {0}")]
    Normal(String),
    #[error("influx error: {0}")]
    Influx(#[source] influxdb::Error)
}

#[cfg(test)]
mod tests {
  use super::*;

  fn test() {
      let err = CustomError::Normal("err".to_string());
      let err1 = CustomError::Normal("err".to_string());
  
      // this assert only works when `PartialEq` is implemented/derived for `CustomError`
      assert_eq!(err, err1)
  }
}

Checklist

  • Formatted code using cargo fmt --all
  • Linted code using clippy (there are warnings, but the reasons for them are not my additions)
    • with reqwest feature: cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features use-serde,derive,reqwest-client -- -D warnings
    • with surf feature: cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features use-serde,derive,hyper-client -- -D warnings
  • Updated README.md using cargo doc2readme -p influxdb --expand-macros
  • Reviewed the diff. Did you leave any print statements or unnecessary comments?
  • Any unfinished work that warrants a separate issue captured in an issue with a TODO code comment

@msrd0
Copy link
Collaborator

msrd0 commented Sep 4, 2023

Hi, thanks for your PR. Why do you compare the Display version of the errors, instead of using the derive macro for (Partial)Eq?

@bytedream
Copy link
Contributor Author

Good point lol. I've just took over the Eq part of my implementation before this PR. Adjusted it

@msrd0 msrd0 merged commit 86f1b59 into influxdb-rs:main Sep 8, 2023
20 of 23 checks passed
@Empty2k12
Copy link
Collaborator

Thanks! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants