erickt / rust-zmq

Rust zeromq bindings.
Apache License 2.0
887 stars 190 forks source link

Use consistent mutability for functions taking `Socket` references #216

Open collosi opened 6 years ago

collosi commented 6 years ago

Functions like set_subscribe() logically change the state in a Socket. Doesn't that mean that it should be declared like "fn set_subscribe(&mut self, value: &[u8]) -> Result<()>"? I understand that the rust type checker might not force you to do that because you're mutating state behind a native pointer, but logically shouldn't it? More importantly, are there optimizations that the compiler might make that are incorrect, because it's assuming nothing related to the socket is changing?

rotty commented 6 years ago

I think that it safe to have all methods take an immutable reference to self, as long as there is no way to obtain a reference to some state within the socket which would be invalidated by some method. I might be mistaken, though, and will try to solicit a second opinion.

rotty commented 5 years ago

I've now renamed this issue. If it is indeed safe and sound to use &Socket for socket setters, it should be safe for other methods as well. This should be resolved with a rationale documented somewhere, and will require an API change.