I am implementing the Display
trait for a type like so:
impl Display for Key {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let modifier = match self.0.modifiers {
KeyModifiers::ALT => Some("alt"),
KeyModifiers::CONTROL => Some("ctrl"),
KeyModifiers::NONE => None,
invalid => bail!("Invalid key modifier provided in keybinding: {:?}", invalid),
};
...
However, the bail!
fails because it expects to return an anyhow::Error
instead of the required std::format::Error
. Any way I can modify the return Result
to be an anyhow error? Or another way to solve this?