romio icon indicating copy to clipboard operation
romio copied to clipboard

implement TryFrom<std::net::UdpSocket/TcpListener> for UdpSocket/TcpListener

Open vavrusa opened this issue 6 years ago • 7 comments

This allows setting various socket options (e.g. SO_REUSEPORT) before binding to the socket, and also socket passing from the service supervisor (e.g. systemd).

vavrusa avatar Jul 25 '19 22:07 vavrusa

Hey thanks so much for this patch!

For work we encountered a similar situation recently (around mio also), and something that came out of it is that if a std component can't be changed to a mio variant, something terrible has gone wrong, and it's probably safe to abort the process.

Which is to say: I think it'd be entirely reasonable to use From rather than TryFrom for these conversions.

yoshuawuyts avatar Jul 29 '19 08:07 yoshuawuyts

Which is to say: I think it'd be entirely reasonable to use From rather than TryFrom for these conversions.

Let the user fail as they want =)

kpp avatar Jul 29 '19 08:07 kpp

It will probably be okay, but I didn't feel confident burying .unwrap() in a fundamental library for just a slightly easier use (this is also not something that will be used that often I guess). That being said, I'm happy to change it if your consensus is to go with From trait instead.

vavrusa avatar Jul 29 '19 18:07 vavrusa

Just to clarify - the "👍" means "it's ok to keep it as it is", "please change it to From", or "undecided" ?

vavrusa avatar Aug 02 '19 06:08 vavrusa

I am against .unwrap() in a library code

kpp avatar Aug 02 '19 08:08 kpp

@vavrusa yeah, I'd prefer if it was From rather than TryFrom. If this fails then something terrible has gone wrong on the mio side, and it's probably best to abort.

@kpp Sorry, but that feels like an arbitrary restriction. If we were to follow that then romio in its current form wouldn't even be able to exist.

yoshuawuyts avatar Aug 02 '19 13:08 yoshuawuyts

Sorry, but that feels like an arbitrary restriction.

It's not. You can add both TryFrom and From, but implement From as try_from().unwrap(). Having only From implemented with .unwrap() is a restriction.

kpp avatar Aug 02 '19 13:08 kpp