-
Notifications
You must be signed in to change notification settings - Fork 385
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
Immutable BlockSource interface #1307
Immutable BlockSource interface #1307
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, &self
in a trait is strictly less flexible than &mut self
- you can always implement the trait as for &mut &Self
, whereas you can't go the other way (&mut &Self
is still a non-mutable reference to Self
). Sure, the double-reference is less efficient, but its at least highly flexible. In this specific case, I could see a BlockSource
being implemented over some kind of pipelined HTTP/etc client where you need exclusive access to an underlying socket to operate. You could "just add a lock" or whatever, but I'm not really entirely sure what the argument on the flip side is, here - when is &mut Self
a real issue for block source implementors?
IIUC, the use case is the need for two |
Right, that specific use-case could be accomplished with an implementation for |
I'm not sure how that's helpful. It won't let you mutate anything within Also seems inconsistent with other traits like |
Right, my point is for those who don't want to mutate and want multiple instances, you can do this trick. For those that do want to mutate, it being
Yea, agreed we should be consistent, I'm just not sure what the right answer is here. |
I take that back, after the discussion at https://app.slack.com/client/TT1FWCE01/C0177366AR2/thread/C0177366AR2-1648897983.912319 I feel like maybe we should go ahead with this. Can you rebase this @jkczyz? |
444d8fb
to
79c4a6d
Compare
Codecov Report
@@ Coverage Diff @@
## main #1307 +/- ##
==========================================
- Coverage 90.83% 90.51% -0.33%
==========================================
Files 73 71 -2
Lines 41266 39210 -2056
Branches 41266 0 -41266
==========================================
- Hits 37486 35489 -1997
+ Misses 3780 3721 -59
Continue to review full report at Codecov.
|
ACK In general, I prefer to keep If the implementor then needs something mutable because of the specific implementation details, then interior mutability seems appropriate. |
Oops, this now conflicts with the changes to Cargo for 106. |
Querying a BlockSource is a logically immutable operation. Use non-mut references in its interface to reflect this, which allows for users to hold multiple references if desired.
79c4a6d
to
3cdbbf5
Compare
Querying a
BlockSource
is a logically immutable operation. Use non-mut
references in its interface to reflect this, which allows for users to hold multiple references if desired.