`graphics::character::CharacterCache>::Error` doesn't require `Debug` trait
golergka opened this issue · 4 comments
I tried to use expect
method on the result of CharacterCache.character
method, but turns out I can't, because the associated Error type doesn't require Debug trait:
error[E0599]: no method named `expect` found for type `std::result::Result<graphics::character::Character<'_, <G as graphics::Graphics>::Texture>, <C as graphics::character::CharacterCache>::Error>` in the current scope
--> src/some_file.rs:44:53
|
44 | let ch_glyph = glyphs.character(34, ch).expect("Couldn't load character");
| ^^^^^^
|
= note: the method `expect` exists but the following trait bounds were not satisfied:
`<C as graphics::character::CharacterCache>::Error : std::fmt::Debug`
It would be obvious to add a constraint that Error should implement the Debug trait. It seems to me as a good idea — however, I'm not sure of it, since I have modest Rust experience. I even asked a question on stack overflow about this pattern.
Anyway, if you guys think it's a good idea, it seems kind of obvious to add the derive to all of it's implementations and I would be glad to do it.
You can use map_err
? https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.map_err
That's what I'm doing in the meanwhile in my own code, yes. However, I wanted not only to make my own hobby project, but contribute to Piston as well — and this seems like a pretty small thing that I can easily implement. I just need your blessing first :)
Or, if you think that it's a bad idea, I'm not really in position to argue — I don't consider myself to know Rust well enough. But I would really appreciate the explanation, because it would educate me on what's a good and bad practice in Rust.
Thanks for the feedback! I checked OpenGL/Gfx/Glium/WGPU/Graphics-Buffer backends and they all use Debug
. I think it will not produce too much trouble to require the Debug
trait.
I think it is a good idea to support this for texture operations too, so I will update piston-texture first.