-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
This issue was copied over from: https://github.com/disneystreaming/weaver-test/issues/266
It was opened by: nigredo-tori
This is inspired by the vault library.
At the moment global resources are indexed by ResourceTags and labels. This has its issues:
- The default
ResourceTagimplementation derives its identity fromClassTag. This leads to a possibility of collisions, as stated in the documentation. The suggested workarounds are monomorphic wrappers or customResourceTaginstances. - Labels mitigate the collision problem somewhat (or, rather, leave it up to discipline). But the labels are not tied to resource types, so it's easy to mix up which labels correspond to which resource.
Instead, we can create objects that are guaranteed to be unique, and which are associated with a specific type. Consider something like this:
// default `equals` - different objects are never equal.
final private class UniqueResourceTag[A](
val description: String
) extends ResourceTag[A] {
def cast(obj: Any): Option[A] = Some(obj.asInstanceOf[A])
}
def unsafeCreateUniqueTag[A](description: String): ResourceTag[A] =
new UniqueResourceTag[A](description)This can be used as follows:
// A "constant" somewhere in a common object
val fooTag = unsafeCreateUniqueTag[Foo]("")
// Inside a suite
global.getR()(fooTag)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 broken equals implentations), and there's no way to mistake the type of the resource it points to.
Metadata
Metadata
Assignees
Labels
No labels