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

Replace WidgetMut methods with free functions. #705

Merged
merged 4 commits into from
Oct 22, 2024
Merged

Conversation

PoignardAzur
Copy link
Contributor

See discussion here #663 and on zulip.

Basically, previous code was using WidgetMut<MyWidget> as a receiver. This can be done when WidgetMut is a local type, but external users wouldn't be able to do it. The result would be that users importing Masonry as a dependency but copy-pasting code from one of our widgets would get compile errors.

This PR switches to a syntax that external crates will be able to use when declaring widgets. It's a more verbose, less readable syntax, but it's unambiguous and doesn't require clever tricks.

We can consider switching back to WidgetMut-as-a-receiver when #![feature(arbitrary_self_types)] or some equivalent gets stabilized. See rust-lang/rust#44874 (comment) for current progress.

@PoignardAzur
Copy link
Contributor Author

This PR was created with heavy assistance from Cursor Tab (an AI-assisted IDE). The workflow with that IDE is that you make a change, then the IDE goes "Oh, so you probably also want to change this line? And this line?" and you go tab-tab-tab as it proposes successive line edits.

I tried to make sure all the changes were signature-only and didn't affect program behavior, but I might have let some slip. I'll try to double-check again later in the day.

@PoignardAzur
Copy link
Contributor Author

All tests except doc tests passed on the first try, so that's encouraging.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

A few small details which need some clarity. But mostly this looks good.

masonry/examples/calc_masonry.rs Show resolved Hide resolved
masonry/src/widget/portal.rs Outdated Show resolved Hide resolved
masonry/src/widget/prose.rs Show resolved Hide resolved
masonry/src/widget/root_widget.rs Outdated Show resolved Hide resolved
Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

Let's land this. Obviously our documentation isn't yet updated to reflect this change, but I presume you'll do that in a follow-up?

@PoignardAzur PoignardAzur added this pull request to the merge queue Oct 22, 2024
@PoignardAzur
Copy link
Contributor Author

Yeah, documentation is very WIP.

Merged via the queue into main with commit f322894 Oct 22, 2024
17 checks passed
@PoignardAzur PoignardAzur deleted the rewrite_widget_mut branch October 22, 2024 13:42
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