cberner / redb

An embedded key-value database in pure Rust
https://www.redb.org
Apache License 2.0
3.07k stars 137 forks source link

feat: Debug for Value and Key to be optional #816

Closed dzmitry-lahoda closed 3 weeks ago

dzmitry-lahoda commented 3 weeks ago
error[E0277]: `User` doesn't implement `Debug`
  --> examples/borsh.rs:12:22
   |
12 | impl redb::Value for User {
   |                      ^^^^ `User` cannot be formatted using `{:?}`
   |
   = help: the trait `Debug` is not implemented for `User`
   = note: add `#[derive(Debug)]` to `User` or manually `impl Debug for User`
note: required by a bound in `Value`
  --> /home/dz/github.com/cberner/redb/src/types.rs:74:18
   |
74 | pub trait Value: Debug {
   |                  ^^^^^ required by this bound in `Value`
help: consider annotating `User` with `#[derive(Debug)]`
   |
8  | #[derive(Debug)]
   |

error[E0277]: `Id` doesn't implement `Debug`
  --> examples/borsh.rs:50:22
   |
50 | impl redb::Value for Id {
   |                      ^^ `Id` cannot be formatted using `{:?}`
   |
   = help: the trait `Debug` is not implemented for `Id`
   = note: add `#[derive(Debug)]` to `Id` or manually `impl Debug for Id`
note: required by a bound in `Value`
  --> /home/dz/github.com/cberner/redb/src/types.rs:74:18
   |

I would like to avoid Debug in our production code, only in test, so Debug for sure does not slows performance.

Debug is optional feature.

cberner commented 3 weeks ago

If you're worried about performance, you should be able to use cfg in your Debug implementation to make it a no-op in production. Is there a reason that doesn't work?

dzmitry-lahoda commented 3 weeks ago

I guess yes, this is workaround. So it will not allow to read behavior out of struct definition.

dzmitry-lahoda commented 3 weeks ago

Also, workaround does not guarant redb does not creates some temporal structures which are compiled away without being created just for Debug.

dzmitry-lahoda commented 3 weeks ago

Debug is poor man json serde kind of, it should be optional feat of redb, like redb could have optional support of some serde kinds of for example.

cberner commented 3 weeks ago

I decided not to add support in redb for serde. You can find the reasoning in past issues, such as this one: https://github.com/cberner/redb/pull/805