Skip to content
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

self mutable reference #4

Closed
MathiasKoch opened this issue Feb 18, 2020 · 3 comments
Closed

self mutable reference #4

MathiasKoch opened this issue Feb 18, 2020 · 3 comments

Comments

@MathiasKoch
Copy link
Collaborator

I am a bit unsure on why this shouldn't have a mutable reference to self?

The way i see it, you would usually implement this on some sort of network client, owning access to a peripheral (unix fd, SPI, I2C, Serial etc.), but most (all?) of these require a mutable reference to be able to send data. This could be fixed by wrapping the peripheral in a RefCell, but even then there is a good chance that the client object would hold stuff like internal state etc that needs to be mutated, meaning that in my particular case, i would end up with a client object of 5 fields, all wrapped in RefCell.

Is this intended behavior, or am i implementing something wrong in general?

@thejpster
Copy link
Member

I had intended implemetors of the crates to handle internal mutability. While in the BSD socket library, I can call open() or write() etc, without having to hold any kind of pointer or reference - it is handled internally by the OS - here, having to hold a non-mutable reference to a particular IP stack seemed like a good compromise.

Requiring a &mut ref would make operating, say, an HTTP client and an SMTP client at the same time almost impossible.

@MathiasKoch
Copy link
Collaborator Author

I think that makes sense. I will go with the internal mutability 👍

@kellerkindt
Copy link

Cross linking to #39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants