I've run into a problem with piston2d-graphics
crate. When I try to use expect()
method on Result
that I get from graphics::character::CharacterCache::character
method, it turns out I can't — because it requires the Error type of the Result to implement std::fmt::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`
Error
here is an associated (nested) type in CharacterCache
trait. I can easily submit a PR that adds the requirement and then add it's implementation with a simple derive macro to all other crates. It seems reasonable, because expect()
and other related methods are used in Rust all the time, but I'm not sure. Is it the Rust way, or are there reasons not to do it?
I describe the question using example of it's occurrence, but it has nothing specific to do with Piston, my question is about general pattern in Rust. So tag rust-piston
is unrelated, please don't add it to the question.
where <C as graphics::character::CharacterCache>::Error : std::fmt::Debug
on the function that callsexpect
(and possibly other functions that call the first one) should solve the problem too. - Francis GagnéDebug
. Nevermind then! - Francis Gagné