mio
mio copied to clipboard
Implement new I/O-safe traits on types
This PR adds a new feature, io_safety
, which implements AsFd
/AsSocket
/From<OwnedFd>
/From<OwnedSocket>
/Into<OwnedFd>
/Into<OwnedSocket>
on the types within mio
. Enabling this feature requires Rust 1.63 or higher.
See also: #1588
Just a heads up: clippy seems to be failing due to the addition of a lint unrelated to this PR
Using features for this kind of stuff is generally an anti-pattern. We can never remove a feature once we add it (remove features is a breaking change), so even if we bumped the MSRV in the future, this feature would need to stay around forever.
The way this situation has been handled in other Tokio crates in the past is to simply wait until the MSRV is bumped far enough to support it without conditional compilation.
Using features for this kind of stuff is generally an anti-pattern. We can never remove a feature once we add it (remove features is a breaking change), so even if we bumped the MSRV in the future, this feature would need to stay around forever.
We could just make it a deprecated feature that does nothing once the MSRV has reached 1.63, but if you don't want to do it that way I'd understand. We could just hold off on it until the MSRV bump.
I think that is probably our best course of action.
Another way to handle this would be to add a build.rs that detects whether the feature is supported. I know that has tradeoffs too, but would that be acceptable here?
I'm afraid this is not going into v0.8, but it's possible for v0.9 as we need to bump the MSRV for https://github.com/tokio-rs/mio/issues/1527 anyway. I see you have the same pr for socket2 (https://github.com/rust-lang/socket2/pull/324), so let's experiment with that first since that is being bumped (to v0.5) sooner.
Closing this, because it needs a rework when the time is right.