JustTweak icon indicating copy to clipboard operation
JustTweak copied to clipboard

Hashable conformance

Open jbehrens94 opened this issue 5 years ago • 3 comments

Hi all,

I was wondering if there'd be a way to make this library Hashable friendly, I've tried conforming TweakValue to Hashable but that causes a lot of compiler errors about TweakValue having associated type or Self requirements. Any advice for this approach?

jbehrens94 avatar Feb 24 '21 20:02 jbehrens94

Tagging you, @albertodebortoli because GitHub probably doesn't automatically email when new issues are created. (At least, in my experience)

jbehrens94 avatar Feb 24 '21 20:02 jbehrens94

HI @jbehrens94, you are right, if you try to make the TweakValue protocol conforming to Hashable you'll get the following all over the place:

Protocol 'TweakValue' can only be used as a generic constraint because it has Self or associated type requirements

Frankly, I don't think it's possible to do what you'd like to do with the current design of the library. It would need some deep redesign and refactoring, probably converting TweakValue to a generic struct (something I've tried in the past and miserably failed).

albertodebortoli avatar Feb 28 '21 18:02 albertodebortoli

I created this PR with some (typical Friday) experimentation to make Tweak and TweakValue conform to Hashable. The PR is just to show a diff on how it could potentially be done using type erasure. It's not meant to be merged

fadyyecob avatar Jan 14 '22 15:01 fadyyecob

Hi @fadyyecob and @jbehrens94. I'm gonna go ahead and close this as we have moved to a different component (Toggles). The changes suggested here are not possible with the design of JustTweak, I suggest taking a look at Toggles as its code should be better in this regard.

albertodebortoli avatar Jan 05 '24 10:01 albertodebortoli