mio icon indicating copy to clipboard operation
mio copied to clipboard

Implement new I/O-safe traits on types

Open notgull opened this issue 2 years ago • 6 comments

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

notgull avatar Aug 11 '22 19:08 notgull

Just a heads up: clippy seems to be failing due to the addition of a lint unrelated to this PR

notgull avatar Aug 11 '22 19:08 notgull

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.

Darksonn avatar Aug 11 '22 21:08 Darksonn

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.

notgull avatar Aug 11 '22 21:08 notgull

I think that is probably our best course of action.

Noah-Kennedy avatar Aug 11 '22 23:08 Noah-Kennedy

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?

sunfishcode avatar Aug 12 '22 14:08 sunfishcode

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.

Thomasdezeeuw avatar Aug 12 '22 16:08 Thomasdezeeuw

Closing this, because it needs a rework when the time is right.

notgull avatar Sep 10 '23 21:09 notgull