zhiburt / tabled

An easy to use library for pretty print tables of Rust structs and enums.
MIT License
1.94k stars 77 forks source link

"the trait `From<std::path::Display<'_>>` is not implemented for `Cow<'_, _>`" #395

Closed elenakrittik closed 5 months ago

elenakrittik commented 5 months ago

The following example results in an error spelled out in the title:

#[derive(tabled::Tabled)]
struct MyStruct<'a> {
    #[tabled(display_with("std::path::Path::display"))]
    path: &'a std::path::Path,
}

tabled only says that it requires types to be Display, but here is it also trying to construct a Cow of something from that Display impl.

zhiburt commented 5 months ago

Hi @elenakrittik Thanks for bringing it up.

tabled only says that it requires types to be Display

True

If what you're saying is true; then it must be considered a bug. (I very much believe it's the case)

Don't you wanna fix it yourself? (Just asking in case you're interested to) It shall be a small fix down here, and a few tests.

https://github.com/zhiburt/tabled/blob/fa06ecfb180649fef55141cae8dfd8db11a8a2c5/tabled_derive/src/lib.rs#L448 https://github.com/zhiburt/tabled/blob/fa06ecfb180649fef55141cae8dfd8db11a8a2c5/tabled_derive/src/lib.rs#L392

Interesting....

Thanks once again. Let me know if you'll have time.

elenakrittik commented 5 months ago

Don't you wanna fix it yourself? (Just asking in case you're interested to) It shall be a small fix down here, and a few tests.

I would be glad to help, but i'm not sure i understand the "real" issue here. I tried playing around with the lines you've mentioned (removing Cow, forcing Cow::Borrowed or Cow::Owned) but in every case the change broke tests and/or examples. I also noticed that Cow is mandatory because the Tabled trait itself mandates return types to be Vec<Cow<...>>. If "fixing" this will get too much into the core of tabled, maybe this should just be documented instead?