Ignore PartialEq implementation for testing

⚓ Rust    📅 2025-09-25    👤 surdeus    👁️ 5      

surdeus

Warning

This post was published 36 days ago. The information described in this article may have changed.

Hello,

I have a struct with other structs in its fields, and I have implemented Debug, Display, and serde Serialize for it, and they all output a single line (string). I have also implemented PartialEq (and derived Eq) to compare this single line.

As you can guess, the serialized line of text doesn't include some additional information from the nested structs - that's ignored for Display, Debug and PartialEq. And that's OK - that's exactly how it should work.

The only time I don't want to ignore the additional information is testing. When I write a test, I want to compare the full struct of structs like I've derived PartialEq instead of implementing it. And ideally, I want to print an error like I derived Debug.

Is that possible?

Thank you.

5 posts - 4 participants

Read full topic

🏷️ Rust_feed