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

Tabled attribute format #398

Merged
merged 8 commits into from
Apr 4, 2024

Conversation

thomassimmer
Copy link
Contributor

@thomassimmer thomassimmer commented Mar 25, 2024

Hello,

This is for #396 .

I hope it's fine, it was probably a bit too difficult for me as a first issue. I tried to do something very similar to display_with but I encounter some difficulties with properties and nested structs/enums. I would be happy to see what corrections you can make to improve it.

By the way, thanks a lot for the library! :)

FYI, I needed that for this project : https://github.com/thomassimmer/NeoPass

Cheers

@thomassimmer thomassimmer force-pushed the tabled-attribute-format branch from 315142c to c94aa8d Compare March 26, 2024 07:03
Copy link
Owner

@zhiburt zhiburt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised that you got this fight 😄

So overall pretty decent 👍 .

I'd have some comments according to style.
But I have them against my own code, and the current state of tabled_derive in particular.... 😥

Let me know what you think and whether,
you will be able to address my comments.

Take care

expected: ["0", "1"], ["0", "foo v2"],
);

// todo : self is the tuple here. It should be the sstr element instead.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good call to test self but what's the issue, exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a tuple and this is what self is representing here, instead it should represent the sstr property of the tuple.

I can't call this property as it's not a struct. Do you see what I mean ?

Copy link
Owner

@zhiburt zhiburt Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow I do believe that self must be a tuple?
no?

@zhiburt
Copy link
Owner

zhiburt commented Mar 29, 2024

And yes, don't worry about merge conflicts.

@zhiburt
Copy link
Owner

zhiburt commented Mar 29, 2024

Am I wrong that with your changes display_with will also support arguments like self.field1.
I bet I am not.

And I bet it's good.

Just need to document and create tests.

@thomassimmer
Copy link
Contributor Author

Am I wrong that with your changes display_with will also support arguments like self.field1. I bet I am not.

And I bet it's good.

Just need to document and create tests.

You are right! I added one test, let me know if it's fine.

@zhiburt zhiburt self-requested a review April 4, 2024 09:24
@zhiburt
Copy link
Owner

zhiburt commented Apr 4, 2024

Hey @thomassimmer

I'll merge it,
will add a few more things,
and release hopefully soon.

But could you let me know your thoughts on this tuple thing?
It seems perfectly good to me.

    #[test]
    fn format3() {
        #[derive(Debug, Tabled)]
        struct StructName(u8, #[tabled(format("foo {} {:?}", 2, self))] String);

        let value = StructName(0, String::from("string"));

        assert_eq!(value.fields(), vec!["0", "foo 2 StructName(0, \"string\")"]);
        assert_eq!(StructName::headers(), vec!["0", "1"]);
    }

Thanks for contribution.
And take care.

@zhiburt zhiburt merged commit 6ce5d34 into zhiburt:master Apr 4, 2024
78 checks passed
@thomassimmer
Copy link
Contributor Author

Hey @thomassimmer

I'll merge it, will add a few more things, and release hopefully soon.

But could you let me know your thoughts on this tuple thing? It seems perfectly good to me.

    #[test]
    fn format3() {
        #[derive(Debug, Tabled)]
        struct StructName(u8, #[tabled(format("foo {} {:?}", 2, self))] String);

        let value = StructName(0, String::from("string"));

        assert_eq!(value.fields(), vec!["0", "foo 2 StructName(0, \"string\")"]);
        assert_eq!(StructName::headers(), vec!["0", "1"]);
    }

Thanks for contribution. And take care.

Hi @zhiburt ,

What you said on tuples sounds good to me too!

Thank you for merging and take care.

@thomassimmer thomassimmer deleted the tabled-attribute-format branch April 5, 2024 07:23
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

Successfully merging this pull request may close these issues.

2 participants