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

tabled/ Add `#[tabled(crate = "")]` attribute #394

Closed zhiburt closed 5 months ago

zhiburt commented 6 months ago

Hi @unmaykr-aftermath

Could you check it out?

close #393

PS: The code got a little bit bloated with this commit; so will require some refactorings

unmaykr-aftermath commented 5 months ago

Nice @zhiburt , it works!

Although it looks slightly different from other crates that define a similar attribute:

    #[move_(crate = af_sui_pkg_sdk::af_move_type)]
    #[serde(crate = "af_sui_pkg_sdk::serde")]
    #[tabled(crate = "af_sui_pkg_sdk")]

I'm not sure if there's a standard out there for this. I can research it when I have the time

zhiburt commented 5 months ago

I'm not sure if there's a standard out there for this. I can research it when I have the time

Interesting; thanks for pointing out; I also do not know to be honest best practice here.

But if you'd do just this, it'd be identical. Except the double quotes.

pub mod unknown_crate {
    pub use ::tabled;
}

use unknown_crate::tabled::Tabled;

#[derive(Tabled)]
#[tabled(crate = "unknown_crate::tabled")]

Or it's different?

zhiburt commented 5 months ago

One question from a beginner macro developer to a more experienced one: did you decide to not use deluxe for attribute parsing? I would be curious if you found something bad about it that I should be aware of. It was useful to me in other projects.

And yes,

According to it.

As I do remember back then there was no such crate. And overall I stick to the idea to not use libs for such a fraction of code. But yeeeeesss just need to do a small refactoring down there :sweat_smile:

unmaykr-aftermath commented 5 months ago

I'm not sure if there's a standard out there for this. I can research it when I have the time

Interesting; thanks for pointing out; I also do not know to be honest best practice here.

But if you'd do just this, it'd be identical. Except the double quotes.

pub mod unknown_crate {
    pub use ::tabled;
}

use unknown_crate::tabled::Tabled;

#[derive(Tabled)]
#[tabled(crate = "unknown_crate::tabled")]

Or it's different?

Spot on, the following worked. Thanks!

    #[tabled(crate = "af_sui_pkg_sdk::tabled")]
unmaykr-aftermath commented 5 months ago

Seems good to go from a functionality point-of-view. Any other feedback you'd like?

zhiburt commented 5 months ago

I'll be released (in a few days I hope).

Thanks @unmaykr-aftermath for bringing the issue to the table.

Take care.

unmaykr-aftermath commented 5 months ago

Hey @zhiburt! Any update on when this may hit crates.io? I think I'll patch my deps for now in order to use the new feature

zhiburt commented 5 months ago

Aahhhh it was supposed to be there for a while.................

I Just think about improving a little bit #398 I think it may be very handy feature.

I've found that doing things like #[tabled(format("{}", self.some_array[0]))] is not possible. Which is a pity....

I could be easily solved, but would break enum inline usage with it. Cause we would refer to enum as self but not substruct.

#[derive(Tabled)]
enum Something {
    #[tabled(inline)]
    Small {
        #[tabled(format("{} {}", self.data, self.data))]
        data: String,
    }
}

It could be changed to next one to work, but I doubt it's a good one.

#[derive(Tabled)]
enum Something {
    #[tabled(inline)]
    Small {
        #[tabled(format("{} {}", data, data))]
        data: String,
    }
}

Maybe in private to have some hack rebuilding inner struct and have a method so self would work.. But yet I have not figured it out. Though it seems very much doable.

So yes, I just thinking what better to do with it.

cc: @unmaykr-aftermath

zhiburt commented 5 months ago

...... Maybe I shall forget about this enum. Though I think it was pretty beautiful on its own.

unmaykr-aftermath commented 4 months ago

Apologies. I was moving homes. I think I can have a look at the enum issue on the weekeend