zhiburt / tabled

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

Feature request: add `#[tabled(crate = ...)]` to allow re-exporting the library #393

Closed unmaykr-aftermath closed 7 months ago

unmaykr-aftermath commented 8 months ago

Problem

I've run into the following issue while developing a macro_rules! macro that auto-implements Tabled for a struct: image cargo clippy output:

 1  error[E0433]: failed to resolve: could not find `tabled` in the list of imported crates

This happens because there are lines like this in the derive implementation: https://github.com/zhiburt/tabled/blob/master/tabled_derive/src/lib.rs#L48

Hence, crates that use my macro will be forced to import both my crate and the tabled crate, which is not great ergonomics.

Request

Add a #[tabled(crate = ...)] that takes as argument the path of the tabled crate. This will allow crates to re-export tabled and let users use their macros without explicitly importing tabled.

Basically the same as serde's #[serde(crate = "...")] attribute.

I have some experience implementing macros like this and can do so for tabled if the community/maintainers agree with the addition.

zhiburt commented 8 months ago

Hi there

Interesting issue.

If you wanna try you can do it; But I can do it myself if you wish, let me know if so.


I guess you'll need to update the struct and use it in the trait emit.

https://github.com/zhiburt/tabled/blob/fa06ecfb180649fef55141cae8dfd8db11a8a2c5/tabled_derive/src/attributes.rs#L77

Take care

unmaykr-aftermath commented 8 months ago

Hi there

Interesting issue.

If you wanna try you can do it; But I can do it myself if you wish, let me know if so.

I guess you'll need to update the struct and use it in the trait emit.

https://github.com/zhiburt/tabled/blob/fa06ecfb180649fef55141cae8dfd8db11a8a2c5/tabled_derive/src/attributes.rs#L77

Take care

@zhiburt If you wanna have a stab at it first, I think I'll only have time next week for it. Thanks for the tip btw!