tokio-rs / prost

PROST! a Protocol Buffers implementation for the Rust Language
Apache License 2.0
3.95k stars 508 forks source link

feat: Relax Message Debug trait bound #1147

Open tottoto opened 2 months ago

tottoto commented 2 months ago

Relaxes Message's Debug trait bound.

BREAKING CHANGE: trait Debug was a supertrait of trait Message. This is no longer required by prost. If your code relies on trait Debug being implemented for every impl Message, you must now explicitly state that you require both Debug and Message. For example: where M: Debug + Message

tottoto commented 2 months ago

Can you explain why this is useful?

When the Debug implementation is not needed, we can use prost_build::Config::skip_debug() to skip implementing Debug. However as the Messages trait requires Debug implementation, it is needed to implement dummy implementation to implement Message when it is not actually needed. Relaxing Message's Debug trait bound requirement removes this.

Is this an API breaking change?

I think this is a breaking change. Previously, when a value's type had a Message bound imposed on it, we could write code that relied on that value implementing Debug, after this change, we will get a compilation error and will need to explicitly state Debug.

caspermeijn commented 2 months ago

Can you explain why this is useful?

When the Debug implementation is not needed, we can use prost_build::Config::skip_debug() to skip implementing Debug. However as the Messages trait requires Debug implementation, it is needed to implement dummy implementation to implement Message when it is not actually needed. Relaxing Message's Debug trait bound requirement removes this.

I see, so skip_debug was already useful to write your own impl Debug. With this change you can use skip_debug to not implement Debug at all. That makes sense.

Is this an API breaking change?

I think this is a breaking change. Previously, when a value's type had a Message bound imposed on it, we could write code that relied on that value implementing Debug, after this change, we will get a compilation error and will need to explicitly state Debug.

I understand. I will prepare this for the next breaking release