Recently I came across this error:
error[E0277]: the trait bound `Input: From<KeyEvent>` is not satisfied
--> src/ui/input.rs:81:22
|
81 | widget.input(key);
| ----- ^^^ the trait `From<KeyEvent>` is not implemented for `Input`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `From<T>`:
<Input as From<crossterm::event::Event>>
<Input as From<crossterm::event::MouseEvent>>
<Input as From<crossterm::event::KeyEvent>>
= note: required for `KeyEvent` to implement `Into<Input>`
note: required by a bound in `TextArea::<'a>::input`
--> /home/kosa/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/tui-textarea-0.4.0/src/textarea.rs:243:41
|
243 | pub fn input(&mut self, input: impl Into<Input>) -> bool {
| ^^^^^^^^^^^ required by this bound in `TextArea::<'a>::input`
which was weird to me because key
is, in fact, a crossterm::event::KeyEvent
.
You can see crossterm::event::KeyEvent
highlighted in the list of types that do implement the To<Input>
trait!
Turns out my Cargo.toml
looked like this:
tui = { package = "ratatui", version = "0.24.0" }
tui-textarea = "0.4.0"
crossterm = { version = "0.26.1", features = ["event-stream"] }
and the Cargo.toml
for tui-textarea
, whose included function I was calling, looked like this:
crossterm = { package = "crossterm", version = "0.27", optional = true }
crossterm-025 = { package = "crossterm", version = "0.25", optional = true }
ratatui = { version = ">=0.23.0, <1", default-features = false, optional = true }
Bumping the version of crossterm
in my project fixed the issue.
Mayhaps, mayhaps. I actually got this error, with the helpful hint provided, like 5 minutes before the trait error because I had the ratatui
crate at 0.23.0
instead of 0.24.0
:
error[E0308]: mismatched types
--> src/ui/input.rs:39:36
|
39 | $textarea.set_cursor_style(Style::default())
| ---------------- ^^^^^^^^^^^^^^^^ expected `ratatui::style::Style`, found a different `ratatui::style::Style`
| |
| arguments to this method are incorrect
...
151 | init_textarea!(self.url, "URL");
| ------------------------------- in this macro invocation
|
= note: `ratatui::style::Style` and `ratatui::style::Style` have similar names, but are actually distinct types
note: `ratatui::style::Style` is defined in crate `ratatui`
--> /home/kosa/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/ratatui-0.23.0/src/style.rs:253:1
|
253 | pub struct Style {
| ^^^^^^^^^^^^^^^^
note: `ratatui::style::Style` is defined in crate `ratatui`
--> /home/kosa/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/ratatui-0.24.0/src/style.rs:192:1
|
192 | pub struct Style {
| ^^^^^^^^^^^^^^^^
= note: perhaps two different versions of crate `ratatui` are being used?
note: method defined here
--> /home/kosa/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/tui-textarea-0.4.0/src/textarea.rs:1941:12
|
1941 | pub fn set_cursor_style(&mut self, style: Style) {
| ^^^^^^^^^^^^^^^^
= note: this error originates in the macro `unfocus_textarea` which comes from the expansion of the macro `init_textarea` (in Nightly builds, run with -Z macro-backtrace for more info)
In the future, I might look into the feasibility of adding something similar to the trait error output, but don’t know the inner workings of the Rust compiler at all…