moxie icon indicating copy to clipboard operation
moxie copied to clipboard

`moxie::Key` is and isn't a smart pointer

Open anp opened this issue 4 years ago • 1 comments

Two API guidelines are in conflict for Key:

  • Smart pointers do not add inherent methods (C-SMART-PTR)
  • Only smart pointers implement Deref and DerefMut (C-DEREF)

Key implements Deref (but not DerefMut), and it adds inherent methods. Its deref impl is useful for sharing the "current state" with app logic as it is.

anp avatar Sep 27 '20 17:09 anp

Key shouldn't implement Deref -- it has footguns! Notably it's pretty easy to rely on the deref behavior immediately after having updated the key, only to find it hasn't actually changed.

anp avatar Sep 27 '20 22:09 anp