Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kdheepak opened this issue Aug 4, 2024 · 0 comments
Open

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

kdheepak opened this issue Aug 4, 2024 · 0 comments

Comments

@kdheepak
Copy link
Collaborator

kdheepak commented Aug 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant