Skip to content

Re-add Display trait on descriptors#54

Merged
staktrace merged 4 commits into
staktrace:mainfrom
simlay:re-add-impl-display-for-descriptors
Apr 6, 2025
Merged

Re-add Display trait on descriptors#54
staktrace merged 4 commits into
staktrace:mainfrom
simlay:re-add-impl-display-for-descriptors

Conversation

@simlay

@simlay simlay commented Apr 6, 2025

Copy link
Copy Markdown
Contributor

Hey hey,

I appreciate this crate and the work you do!

I was going about upgrading from 0.6 to 0.8 in jaffi and noticed that impl Display was removed in #47.

Additionally, the Display trait is no longer implemented by these types - however I'm open to adding that back if there is demand for it.

So I re-added it as it's used for the method name generation. This is an example of the name generation. If I use the Debug representation it's pretty gross (and would also be a breaking change).

Comment thread src/descriptors.rs Outdated
impl<'a> fmt::Display for ClassName<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let segments : Vec<Cow<'a, str>> = self.segments.iter().map(|s| s.name.clone()).collect();
write!(f, "{}", segments.join("/"))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Joining on / isn't quite perfect here as I think the segments can also separated by ;. Thoughts?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

There's just one ; at the end, to mark the end of the class name descriptor. So this is fine, just needs a ; appended

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm. Unclear why but the addition of ; breaks things for me in the jaffi PR.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Oh I missed the ; was being added at the callsite where you serialize the L{}; - so your original implementation was right, don't need the extra ;, sorry!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah Cool. #56 fixes that!

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, I've merged that and some test changes too. Published everything as 0.8.1. Cheers!

@staktrace staktrace left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This looks good, just a couple of comments below.

Comment thread src/descriptors.rs Outdated
impl<'a> fmt::Display for ClassName<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let segments : Vec<Cow<'a, str>> = self.segments.iter().map(|s| s.name.clone()).collect();
write!(f, "{}", segments.join("/"))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

There's just one ; at the end, to mark the end of the class name descriptor. So this is fine, just needs a ; appended

Comment thread src/descriptors.rs Outdated

impl fmt::Display for FieldDescriptor<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
if self.dimensions > 0 {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Don't need the if/else here, if dimensions is 0 then the repeat call will already return an empty string. So the if branch already handles both cases correctly

@staktrace staktrace merged commit 037f152 into staktrace:main Apr 6, 2025
@simlay

simlay commented Apr 6, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review and merge! If I can't fix the jaffi side of things nicely, I might author more changes here!

@simlay simlay mentioned this pull request Apr 6, 2025
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