-
Notifications
You must be signed in to change notification settings - Fork 82
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
Make functions that modify underlying state through SPI receive &mut self
instead of &self
#55
Comments
BlockDevice::read
and BlockDevice::write
receive &mut self
&mut self
instead of &self
&mut self
instead of &self
&mut self
instead of &self
I also looked through some of the dependents on crates.io: The only implementor of |
I'm working on an alternative implementation here: https://github.com/datdenkikniet/embedded-sdmmc-rs/tree/no_more_immutable |
Have you looked through the closed issues? There have been related discussions in the past. |
I tried my best to find similar issues, and linked some of them. However, in those issues the reasoning given is that it would be impossible/very impractical to have multiple file systems on a single block device. I don't understand why the choice was made to make For an example of what I mean, see for instance here and here. Instead of forcing the user to accept the usage of a I'm trying to understand why the design choice was made (presumably because it is definitely the most straightforward: users of the library don't have to think about how it works), and why (if for any specific reason at all) changing it would be off the table. |
Maybe @thejpster has some further reasoning for this interface choice? |
Yeah, that's what I was hoping for too :) |
So I haven't thought about this crate in a long time. My recollection is that a function like The If you'd like to submit a PR that removes the RefCell and makes the user deal with |
I see, thanks for the info! I'm cooking up a little something, and can ping again here once it's more or less done, and if it seems like the API can be on a similar level of user-friendliness. So far I've finished implementing reading files and directories, but need to figure out how to do writing and reading at some point while staying ergonomic. |
I never did finish my work on this, and with #79 it may not make any sense at all :) I'm closing this for now |
Currently,
BlockDevice::read
andBlockDevice::write
(and practically all functions inSdMmcSpi
andBlockSpi
) receive&self
.Why is this done?
In my opinion, they should receive
&mut self
, so that responsibility of choosing what method of resource sharing a user wants is up to the user. Issues such as #37 could easily be avoided, and would also make more sense logically:write
ing something is clearly modifying something, so why does it not need mutable access?Especially in embedded settings (which this crate is intended for), where being interrupted while having a borrow is quite possible, I don't quite understand why this design choice was made.
I'm willing to contribute a design proposal and PRs to make this change, if it is deemed that this change makes sense.
This issue is, in essence, the same as #8, but for slightly different reasons. I hope that the reasons mentioned there may have disappeared in the mean time (I can't find a concrete example of why it was dismissed back then). If these issues persist, I would propose that we clearly document that
SdMmcSpi
makes use ofRefCell
s internally.The text was updated successfully, but these errors were encountered: