Git Product home page Git Product logo

Comments (13)

ghedo avatar ghedo commented on July 29, 2024

Hello,

Connection is self-referencing, so it can't be moved or the internal reference (which is actually a raw pointer) would become invalid. So we use Box to get a more stable address on the heap. In theory we should use Pin<Box<...>> but Pin doesn't expose the APIs we need.

from quiche.

NeoLegends avatar NeoLegends commented on July 29, 2024

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. :)

from quiche.

ghedo avatar ghedo commented on July 29, 2024

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.

from quiche.

NeoLegends avatar NeoLegends commented on July 29, 2024

I could file a PR to do this. I'd just need some guidance as to what to do with the documentation on Connections methods. Should they move to the newtype or be copied (so that they'd exist twice)? And also, would you be fine with moving the connection implementation from lib.rs into a separate module, so that lib.rs solely wraps Connection into a newtype and exports the public API surface?

from quiche.

ghedo avatar ghedo commented on July 29, 2024

@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.

from quiche.

RReverser avatar RReverser commented on July 29, 2024

e.g. the public Connection APIs would need to be duplicated to handle the wrapped

I don't think this is true - you already accept it by reference, and it will be perfectly fine to pass pointer from Box as if it was a pointer to unwrapped structure.

from quiche.

ghedo avatar ghedo commented on July 29, 2024

@RReverser if I understand correctly, the proposal here is to have something like pub struct ConnectionWrapper(Box<Connection>) and make Connection itself private, so you'd have to mirror the private Connection API in ConnectionWrapper.

from quiche.

NeoLegends avatar NeoLegends commented on July 29, 2024

@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.

from quiche.

cramertj avatar cramertj commented on July 29, 2024

Connection is self-referencing, so it can't be moved or the internal reference (which is actually a raw pointer) would become invalid. So we use Box to get a more stable address on the heap. In theory we should use Pin<Box<...>> but Pin doesn't expose the APIs we need.

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 Pin<Box<Connection>> wouldn't allow?

from quiche.

ghedo avatar ghedo commented on July 29, 2024

@cramertj basically this rust-lang/rust#60245, though it could potentially be implemented in some other uglier way.

from quiche.

NeoLegends avatar NeoLegends commented on July 29, 2024

@ghedo i believe the required features will be stabilized as part of 1.39. rust-lang/rust#63985

from quiche.

ghedo avatar ghedo commented on July 29, 2024

Yep, I made that PR :)

from quiche.

ghedo avatar ghedo commented on July 29, 2024

Made #249 based on Rust 1.39.

from quiche.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.