TeXitoi / keyberon

A rust crate to create a pure rust keyboard firmware.
MIT License
1.05k stars 79 forks source link

Action/Layout: Explicit the Debug trait to be able to use it #126

Closed borisfaure closed 10 months ago

borisfaure commented 10 months ago

While adding debug lines in some tests, I encountered the following issue:

error[E0277]: `T` doesn't implement `core::fmt::Debug`
   --> src/layout.rs:462:37
    |
462 |         log::info!("do_action{:?}", action);
    |                                     ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `core::fmt::Debug`
    |
    = note: this error originates in the macro `$crate::__private_api::format_args` which comes from the expansion of the macro `log::info` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
    |
341 | impl<const C: usize, const R: usize, const L: usize, T: 'static + core::fmt::Debug, K: 'static + Copy>
    |                                                                 ++++++++++++++++++

error[E0277]: `K` doesn't implement `core::fmt::Debug`
   --> src/layout.rs:462:37
    |
462 |         log::info!("do_action{:?}", action);
    |                                     ^^^^^^ `K` cannot be formatted using `{:?}` because it doesn't implement `core::fmt::Debug`
    |
    = note: this error originates in the macro `$crate::__private_api::format_args` which comes from the expansion of the macro `log::info` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
    |
341 | impl<const C: usize, const R: usize, const L: usize, T: 'static, K: 'static + Copy + core::fmt::Debug>
    |                                                                                    ++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.

(can also be found on https://github.com/borisfaure/keyberon/tree/showcase_debug_issue )

This commit fixes that problem and helps developing new features on keyberon.

TeXitoi commented 10 months ago

You don't need these modification to be able to use the Debug trait. Why did you had to do that? i.e. can you give an example of what you want to do that doesn't work without this change and that work with?

borisfaure commented 10 months ago

Small example here: https://github.com/borisfaure/keyberon/commit/9241347dd29d3a3352c3234cccee44728918ccf3 Honestly, I was surprised I had to do it

TeXitoi commented 10 months ago

You had to do it because you added logs in the impl. Outside, with an explicit T and K type, you don't need this.

This modification force people to have Debug T and K types, so it adds constraints to users that's don't need the feature.

borisfaure commented 10 months ago

Makes sense. I'm closing it.