ratatui / ratatui-macros

Macros for simplifying boilerplate for creating UI using Ratatui.
https://ratatui.rs
MIT License
24 stars 2 forks source link

Make `text![["hello", "world"], "bye"]` work? #64

Open kdheepak opened 1 month ago

kdheepak commented 1 month ago

When using the macros I'm able to write this:

        let text = text![line!["hello", "world"], "world"];

But I get a compile error when I write this:

        let text = text![vec!["hello", "world"], "world"];

or

        let text = text![["hello", "world"], "world"];

I thought the individual exprs would be converted to a Line, but I get this compile error:

image
error[E0277]: the trait bound `ratatui::prelude::Line<'_>: From<Vec<&str>>` is not satisfied
  --> src/text.rs:48:19
   |
48 |             $line.into(),
   |                   ^^^^ the trait `From<Vec<&str>>` is not implemented for `ratatui::prelude::Line<'_>`, which is required by `Vec<&str>: Into<_>`
...
75 |         let text = text![vec!["hello", "world"], "world"];
   |                    -------------------------------------- in this macro invocation
   |
   = help: the following other types implement trait `From<T>`:
             <ratatui::prelude::Line<'a> as From<&'a str>>
             <ratatui::prelude::Line<'a> as From<String>>
             <ratatui::prelude::Line<'a> as From<Vec<ratatui::prelude::Span<'a>>>>
             <ratatui::prelude::Line<'a> as From<ratatui::prelude::Span<'a>>>
   = note: required for `Vec<&str>` to implement `Into<ratatui::prelude::Line<'_>>`
   = note: this error originates in the macro `text` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `ratatui-macros` (lib test) due to 1 previous error

which I was surprised by because I don't get the compile error here:

        let a = ["hello", "world"];
        let x = Line::from(vec!["hello", "world"]);
        let y = Line::from(a);
        let z: Line = ["hello", "world"].into();

Any idea what is going on here? Is there a way to make this work? I tried changing the macro code to ratatui::text::Line::from($line), instead of $line.into() and that didn't work either.