-
Notifications
You must be signed in to change notification settings - Fork 720
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
Why is the Connection boxed by default? #45
Comments
Hello,
|
Ahh, thanks for the clarification. One more question: could this be hidden inside Connection‘s API? This feels like a nitty gritty API internal to me that shouldn‘t be exposed to the user (at least from my limited understanding). Especially because the user might be tempted to move the connection out of the box, effectively breaking it. For example, Connection could be made into a newtype around the current Connection. And if that‘s not possible, I think it should at least be documented that the boxing is intentional. :) |
I'm not sure the indirection of wrapping Connection would be worth the effort, though I do agree that this should be documented. I'll reopen the issue to track that part. |
I could file a PR to do this. I'd just need some guidance as to what to do with the documentation on |
@NeoLegends it's not only about actually having to do the initial work to implement that, but the maintainance burden the change adds in the future (e.g. the public Connection APIs would need to be duplicated to handle the wrapped, which makes it somewhat harder to understand and add new APIs). So for the moment I'd rather not do anything more than documenting the current situation. We can always reconsider in the future. |
I don't think this is true - you already accept it by reference, and it will be perfectly fine to pass pointer from |
@RReverser if I understand correctly, the proposal here is to have something like |
@ghedo Correct. I think though, that the additional maintenance overhead will be minimal and that the safety gains outweigh this. When I made my first tests (and bumped into the questions I asked), the newtype added a mere 100 lines or so to lib.rs, not including some one-time churn like converting connect / accept to return the newtype and so on. |
FWIW there's nothing stopping users from pulling the connection out of the box and putting it back in another one, triggering UB. What specific APIs do y'all need that |
@cramertj basically this rust-lang/rust#60245, though it could potentially be implemented in some other uglier way. |
@ghedo i believe the required features will be stabilized as part of 1.39. rust-lang/rust#63985 |
Yep, I made that PR :) |
Made #249 based on Rust 1.39. |
Due to the fact that we store a pointer to the Connection object inside its own Handshake context, Connection objects cannot be moved (which is why we return a boxed object from its constructor). Using Pin on it makes the compiler enforce this. Fixes #45.
Due to the fact that we store a pointer to the Connection object inside its own Handshake context, Connection objects cannot be moved (which is why we return a boxed object from its constructor). Using Pin on it makes the compiler enforce this. Fixes #45.
Hey,
I was just skimming over the API and I was wondering why
connect
andaccept
return a boxedConnection
?Connection
is neither a trait object nor dynamically sized, so why the need for the box?The text was updated successfully, but these errors were encountered: