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

Allow types generated with prop_extractor! to implement Hash, PartialEq, and Eq trivially #447

Merged
merged 1 commit into from
May 16, 2024

Conversation

timboudreau
Copy link
Contributor

Implements Hash, PartialEq and Eq on ExtratorField where R::Type also implements that trait, and enables the prop_extractor! macro to accept zero or more attributes preceding the type definition.

Rationale: Makes implementing these traits as simple as it would be in an ordinary struct declaration.

Use-case: In my particular case, I have some expensive-to-recompute bezier paths which are computed once in my View's layout function; and some relatively trivial to recompute coordinates that change more often, and indicator which points to some position on those paths. By keeping a hash of those properties that could require recomputation of the path (line size, component size, things like that) I can avoid recomputing the more expensive things unless something really changed that invalidates the cached value.

Originally this code was simply a standalone struct type, but since many of the properties make sense as style properties, I'm attempting to migrate this code to use style properties where possible - and the ability to simply add #[derive(PartialEq, Eq, Hash)] just inside the prop_extractor! invocation simplifies the implementation.

…alEq, Eq trivially

Implements `Hash`, `PartialEq` and `Eq` on `ExtratorField` where `R::Type` also implements that
trait, and enables the `prop_extractor!` macro to accept zero or more attributes preceding the
type definition.

Rationale: Makes implementing these traits as simple as it would be in an ordinary `struct` declaration.

Use-case: In my particular case, I have some expensive-to-recompute bezier paths which are computed once
in my `View`'s `layout` function; and some relatively trivial to recompute coordinates that change more
often, and indicator which points to some position on those paths.  By keeping a hash of those properties
that could require recomputation of the path (line size, component size, things like that) I can avoid
recomputing the more expensive things unless something really changed that invalidates the cached value.

Originally this code was simply a standalone struct type, but since many of the properties make sense
as style properties, I'm attempting to migrate this code to use style properties where possible - and
the ability to simply add `#[derive(PartialEq, Eq, Hash)]` just inside the `prop_extractor!` invocation
simplifies the implementation.
@dzhou121 dzhou121 merged commit 7e5dd27 into lapce:main May 16, 2024
7 checks passed
@timboudreau timboudreau deleted the style_equality branch May 16, 2024 18:15
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