-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add explicit unique ResourceTag-like keys #107
Comments
This comment was copied over from: disneystreaming/weaver-test#266 (comment) Hello, and thank you for raising an issue
As a matter of fact they are : ie the ResourceMap is keyed by
Yes, and for this very reason we are protecting against it via forcing implicit ambiguity when collisions are possible (ie compile error rather than surprising runtime behaviour), and we've made the conscious decision to leave the API flexible enough so that users can bring in their own patterns (exactly like what you suggest if they want to use that). The reason why I don't want to support your suggestion out of the box is that, unlike vault's examples, it's impossible to pass the values around logically, from the creation of a key, to its use. So such instances have to be instantiated globally, and for it to work, they have to be assigned to a So I'm more inclined to let this problem be solved by users when they encounter it, than introducing a new construct which is inherently risky without macros, and I don't really want to have to maintain more macros than what we already have. The existing solution might not be perfect, but at least mis-using classtag-based resourceTags lead to compile errors. However, I'd be willing make a version of |
This comment was copied over from: disneystreaming/weaver-test#266 (comment)
I guess I didn't phrase it right. Let's say I have Instead, if I had a single
Fair point. I can't say for sure whether guarding this with macros would be warranted, but if you think it would be, then this becomes a non-trivial undertaking. Since I can rely on my coworkers being principled enough, I'm fine with keeping the "dangerous" version in our in-house "bits and bobs" library. 😄 |
This comment was copied over from: disneystreaming/weaver-test#266 (comment)
👍 that sounds like a good work environment 😄
So would a method that takes tags explicitly be a satisfying middle-ground ? |
This comment was copied over from: disneystreaming/weaver-test#266 (comment)
Yes. |
This issue was copied over from: disneystreaming/weaver-test#266
It was opened by: nigredo-tori
This is inspired by the vault library.
At the moment global resources are indexed by
ResourceTag
s and labels. This has its issues:ResourceTag
implementation derives its identity fromClassTag
. This leads to a possibility of collisions, as stated in the documentation. The suggested workarounds are monomorphic wrappers or customResourceTag
instances.Instead, we can create objects that are guaranteed to be unique, and which are associated with a specific type. Consider something like this:
This can be used as follows:
The current API is obviously not perfect for this, but the general idea should be clear enough. Note that there's no way for
fooTag
to collide with anything else (assuming no brokenequals
implentations), and there's no way to mistake the type of the resource it points to.The text was updated successfully, but these errors were encountered: