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

πŸ§‘β€πŸ’» zv, zn: Improve Str, Owned*Name, BusName Debug impls #450

Merged
merged 3 commits into from Aug 22, 2023

Conversation

SeaDve
Copy link
Contributor

@SeaDve SeaDve commented Aug 19, 2023

This PR reduces Debug impls verbosity but retains possibly useful information.

See also #394

Before:

Str::from_static("hello") = Str(
    Static(
        "hello",
    ),
)
Str::from("hello") = Str(
    Borrowed(
        "hello",
    ),
)
Str::from(String::from("hello")) = Str(
    Owned(
        "hello",
    ),
)
UniqueName::from_static_str_unchecked(":1.2") = UniqueName(
    Str(
        Static(
            ":1.2",
        ),
    ),
)
OwnedUniqueName::from(UniqueName::from_static_str_unchecked(":1.2")) = OwnedUniqueName(
    UniqueName(
        Str(
            Static(
                ":1.2",
            ),
        ),
    ),
)
WellKnownName::from_static_str_unchecked("org.gnome.Console") = WellKnownName(
    Str(
        Static(
            "org.gnome.Console",
        ),
    ),
)
OwnedWellKnownName::from(WellKnownName::from_static_str_unchecked("org.gnome.Console")) = OwnedWellKnownName(
    WellKnownName(
        Str(
            Static(
                "org.gnome.Console",
            ),
        ),
    ),
)
BusName::Unique(UniqueName::from_static_str_unchecked(":1.2")) = Unique(
    UniqueName(
        Str(
            Static(
                ":1.2",
            ),
        ),
    ),
)
BusName::WellKnown(WellKnownName::from_static_str_unchecked("org.gnome.Console")) = WellKnown(
    WellKnownName(
        Str(
            Static(
                "org.gnome.Console",
            ),
        ),
    ),
)
OwnedBusName::from(BusName::Unique(UniqueName::from_static_str_unchecked(":1.2"))) = OwnedBusName(
    Unique(
        UniqueName(
            Str(
                Static(
                    ":1.2",
                ),
            ),
        ),
    ),
)
OwnedBusName::from(BusName::WellKnown(WellKnownName::from_static_str_unchecked("org.gnome.Console"))) = OwnedBusName(
    WellKnown(
        WellKnownName(
            Str(
                Static(
                    "org.gnome.Console",
                ),
            ),
        ),
    ),
)
ErrorName::from_static_str_unchecked("org.gnome.Console.Error") = ErrorName(
    Str(
        Static(
            "org.gnome.Console.Error",
        ),
    ),
)
OwnedErrorName::from(ErrorName::from_static_str_unchecked("org.gnome.Console.Error")) = OwnedErrorName(
    ErrorName(
        Str(
            Static(
                "org.gnome.Console.Error",
            ),
        ),
    ),
)
InterfaceName::from_static_str_unchecked("org.gnome.Console.Interface") = InterfaceName(
    Str(
        Static(
            "org.gnome.Console.Interface",
        ),
    ),
)
OwnedInterfaceName::from(InterfaceName::from_static_str_unchecked("org.gnome.Console.Interface")) = OwnedInterfaceName(
    InterfaceName(
        Str(
            Static(
                "org.gnome.Console.Interface",
            ),
        ),
    ),
)
MemberName::from_static_str_unchecked("Member") = MemberName(
    Str(
        Static(
            "Member",
        ),
    ),
)
OwnedMemberName::from(MemberName::from_static_str_unchecked("Member")) = OwnedMemberName(
    MemberName(
        Str(
            Static(
                "Member",
            ),
        ),
    ),
)

After:

Str::from_static("hello") = "hello"
Str::from("hello") = "hello"
Str::from(String::from("hello")) = "hello"
UniqueName::from_static_str_unchecked(":1.2") = UniqueName(
    ":1.2",
)
OwnedUniqueName::from(UniqueName::from_static_str_unchecked(":1.2")) = OwnedUniqueName(
    ":1.2",
)
WellKnownName::from_static_str_unchecked("org.gnome.Console") = WellKnownName(
    "org.gnome.Console",
)
OwnedWellKnownName::from(WellKnownName::from_static_str_unchecked("org.gnome.Console")) = OwnedWellKnownName(
    "org.gnome.Console",
)
BusName::Unique(UniqueName::from_static_str_unchecked(":1.2")) = BusName::Unique(
    ":1.2",
)
BusName::WellKnown(WellKnownName::from_static_str_unchecked("org.gnome.Console")) = BusName::WellKnown(
    "org.gnome.Console",
)
OwnedBusName::from(BusName::Unique(UniqueName::from_static_str_unchecked(":1.2"))) = OwnedBusName::Unique(
    ":1.2",
)
OwnedBusName::from(BusName::WellKnown(WellKnownName::from_static_str_unchecked("org.gnome.Console"))) = OwnedBusName::WellKnown(
    "org.gnome.Console",
)
ErrorName::from_static_str_unchecked("org.gnome.Console.Error") = ErrorName(
    "org.gnome.Console.Error",
)
OwnedErrorName::from(ErrorName::from_static_str_unchecked("org.gnome.Console.Error")) = OwnedErrorName(
    "org.gnome.Console.Error",
)
InterfaceName::from_static_str_unchecked("org.gnome.Console.Interface") = InterfaceName(
    "org.gnome.Console.Interface",
)
OwnedInterfaceName::from(InterfaceName::from_static_str_unchecked("org.gnome.Console.Interface")) = OwnedInterfaceName(
    "org.gnome.Console.Interface",
)
MemberName::from_static_str_unchecked("Member") = MemberName(
    "Member",
)
OwnedMemberName::from(MemberName::from_static_str_unchecked("Member")) = OwnedMemberName(
    "Member",
)

Fixes #431.

This makes Debug impls of Str transparent

Before:

Str(Static("foo"))

After:

"foo"
@zeenix
Copy link
Contributor

zeenix commented Aug 19, 2023

@SeaDve Many thanks! Before I look into the actual commits, could you please summarize what's the different with #394?

> Str::from_static("hello") = "hello"
> Str::from("hello") = "hello"
> Str::from(String::from("hello")) = "hello"
> UniqueName::from_static_str_unchecked(":1.2") = UniqueName(
>     ":1.2",
> )

Looking nice! should we maybe not split it over multiple lines anymore? I think it was only needed when the format was too verbose and hard to follow.

@SeaDve
Copy link
Contributor Author

SeaDve commented Aug 19, 2023

Before I look into the actual commits, could you please summarize what's the different with #394?

From user side, instead of making everything look like a string when printing its debug representation, it still retain the wrapper info, e.g., MemberName("foo"), WellKnownName("foo") etc.

On the similarities with #394, this also removed the information that it is Owned or Borrowed, etc., i.e., Str(Borrowed("foo")) is just "foo". Owned*Name("foo") is just *Name("foo"). I think the commit messages summarizes it pretty well.

should we maybe not split it over multiple lines anymore?

It is up to the formatter. I currently just copied the output from the dbg! macro

Copy link
Contributor

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

LGTM otherwise. Thanks for writing good commit messages.

zbus_names/src/bus_name.rs Show resolved Hide resolved
@SeaDve
Copy link
Contributor Author

SeaDve commented Aug 21, 2023

I am not sure how to handle this on OwnedBusName ; how would it print the inner? Before the latest commits, it prints UniqueName("foo"), but now it is just OwnedBusName("foo")

This makes Debug impls of Owned*Name transparent

Before:

Owned*Name(*Name("foo"))

After:

Owned*Name("foo")
@zeenix
Copy link
Contributor

zeenix commented Aug 21, 2023

I am not sure how to handle this on OwnedBusName ; how would it print the inner? Before the latest commits, it prints UniqueName("foo"), but now it is just OwnedBusName("foo")

In case of OwnedBusName, why not have the inner field output its debug? So it becomes OwnedBusName(UniqueName("foo")).

@SeaDve
Copy link
Contributor Author

SeaDve commented Aug 21, 2023

I am not sure how to handle this on OwnedBusName ; how would it print the inner? Before the latest commits, it prints UniqueName("foo"), but now it is just OwnedBusName("foo")

In case of OwnedBusName, why not have the inner field output its debug? So it becomes OwnedBusName(UniqueName("foo")).

That would make it inconsistent with BusName

@zeenix
Copy link
Contributor

zeenix commented Aug 21, 2023

In case of OwnedBusName, why not have the inner field output its debug? So it becomes OwnedBusName(UniqueName("foo")).

That would make it inconsistent with BusName

Right. Then I am confused what the problem is? πŸ€” If BusName -> BusName("foo") then OwnedBusName -> OwnedBusName("foo") as well?

@SeaDve
Copy link
Contributor Author

SeaDve commented Aug 21, 2023

In case of OwnedBusName, why not have the inner field output its debug? So it becomes OwnedBusName(UniqueName("foo")).

That would make it inconsistent with BusName

Right. Then I am confused what the problem is? πŸ€” If BusName -> BusName("foo") then OwnedBusName -> OwnedBusName("foo") as well?

BusName is currently UniqueName("foo") per the last commits in the PR.

I also think the well-known/unique distinction is pretty useful.

I wonder if we can do BusName::Unique("foo"), and thus OwnedBusName::Unique("foo"), if it is still idiomatic in rust debug impls

@zeenix
Copy link
Contributor

zeenix commented Aug 21, 2023

BusName is currently UniqueName("foo") per the last commits in the PR.

I also think the well-known/unique distinction is pretty useful

ah ok, yeah I see the issue.

I wonder if we can do BusName::Unique("foo"), and thus OwnedBusName::Unique("foo"), if it is still idiomatic in rust.

Hmm.. why not? I'd say go for that.

@SeaDve
Copy link
Contributor Author

SeaDve commented Aug 21, 2023

Hmm.. why not? I'd say go for that.

Sure. However, I will update the PR tomorrow morning as I am currently in bed

@zeenix
Copy link
Contributor

zeenix commented Aug 21, 2023

Sure. However, I will update the PR tomorrow morning as I am currently in bed

For sure, it's nothing urgent. :)

This makes Debug impl of BusName transparent

Before:

Unique(UniqueName("foo"))

After:

BusName::Unique("foo")
@SeaDve
Copy link
Contributor Author

SeaDve commented Aug 22, 2023

I have push the modifications, and also updated the PR comment on how debug prints look

@zeenix zeenix merged commit 412b349 into dbus2:main Aug 22, 2023
7 checks passed
@zeenix
Copy link
Contributor

zeenix commented Aug 22, 2023

@SeaDve Many thanks for your efforts here!

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.

Simplify/Improve Debug implementations
2 participants