You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implementing PrimaryKey and Prefixer outside of storage-plus doesn't seems scary at all (you just want to use your type as a key, why not to?), but there is an issue - if done improperly it may break things. Trivial example is making a type like:
With an Ord implementation which compares firstly on primary, then on secondary. Then when calling .range(..) on such key, I expect them being sorted with my Ord implementation, but they come in different one, because they are sorted basing on their internal binary representation (basically bitwise lexografical order is used). And even worse, when using Bounds on such key I would get random items.
I have 3 proposal to work it around:
Making PrimaryKey and Prefixerunsafe - this would not prevent from implementing them externally, but it would bring attention to the reasons why they are marked as not safe to implement. In the documentation there should be an additional explanation about how keys are compared and how to properly implement them.
Making PrimaryKey and Prefixer sealed traits which is trivial, but prevents implementing them outside the crate at all. (which might be useful for some custom keys when done correctly)
Implementing
PrimaryKeyandPrefixeroutside of storage-plus doesn't seems scary at all (you just want to use your type as a key, why not to?), but there is an issue - if done improperly it may break things. Trivial example is making a type like:With an
Ordimplementation which compares firstly on primary, then on secondary. Then when calling.range(..)on such key, I expect them being sorted with myOrdimplementation, but they come in different one, because they are sorted basing on their internal binary representation (basically bitwise lexografical order is used). And even worse, when usingBoundson such key I would get random items.I have 3 proposal to work it around:
PrimaryKeyandPrefixerunsafe- this would not prevent from implementing them externally, but it would bring attention to the reasons why they are marked as not safe to implement. In the documentation there should be an additional explanation about how keys are compared and how to properly implement them.PrimaryKeyandPrefixersealed traits which is trivial, but prevents implementing them outside the crate at all. (which might be useful for some custom keys when done correctly)Ord, but it would require reversing conversions of key to&[u8], so it is blocked by Better return values from range/prefix cw-plus#198.