Generalize IO Traits for Arc<T> where &T: IoTrait#155684
Generalize IO Traits for Arc<T> where &T: IoTrait#155684rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Arc<T> where &T: IoTrait#155684Conversation
|
This was proposed before in #94744 |
|
if you have some type that depends on using the shared reference itself (and not just data it points to) to keep track of position, this impl would be incorrect since it doesn't keep the shared reference around, but instead creates a new one from the it could be made correct by adding a new trait bound #[unstable(...)]
pub trait SharedSeek
where
for<'a> &'a Self: Seek,
{
}
impl<T: ?Sized + SharedSeek> Seek for Arc<T>
where
for<'a> &'a Self: Seek,
{
...
}
impl SharedSeek for File {}
// ... |
2cccf0f to
9008194
Compare
Seek for Arc<File> for all &T: SeekArc<T> where &T: IoTrait
|
r? @jhpratt rustbot has assigned @jhpratt. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
I've adjusted the approach here to instead add a marker trait to opt-in to the blanket implementation, which should resolve this concern from #94744. This is still useful as the marker trait can (eventually) be moved into Noting here: I believe these could be replaced with |
9008194 to
4e14cec
Compare
Added a marker trait `IoHandle` which can be used by the standard library to opt-in types to a blanket implementation of the various IO traits on `Arc<T>` where `&T: IoTrait` for some `IoTrait`. The marker is required to avoid types like `Arc<[u8]>` being included, since they don't have interior mutability and would not give expected results.
4e14cec to
7ba9478
Compare
|
LGTM; this definitely resolves the concern brought up in the previous attempt. Agreed on the name not much mattering, as the documentation makes it clear. "Handle" is a typical term for this sort of thing anyways. @bors r+ |
Rollup of 9 pull requests Successful merges: - #155684 (Generalize IO Traits for `Arc<T>` where `&T: IoTrait`) - #155081 (Move and clean up some ui test) - #155379 (Avoid query cycles in DataflowConstProp) - #155663 (Eliminate `CrateMetadataRef`.) - #155669 (Add `Sender` diagnostic item for `std::sync::mpsc::Sender`) - #155698 (Syntactically reject tuple index shorthands in struct patterns to fix a correctness regression) - #155703 (Remove myself as a maintainer of `wasm32-wasip1-threads`) - #155706 (Remove `AttributeLintKind` variants - part 7) - #155712 (Forbid `*-pass` and `*-fail` directives in tests/crashes)
Rollup merge of #155684 - bushrat011899:blanket_io_seek_for_ref, r=jhpratt Generalize IO Traits for `Arc<T>` where `&T: IoTrait` ACP: rust-lang/libs-team#755 Tracking issue: #154046 Related: #94744 ## Description After experimenting with #155625, I noticed `Seek` and `SeekFrom` can almost be moved to `core::io`. Unfortunately, the implementation of `Seek` for `Arc<File>` is a blocker for such a move, since `Arc` is not a fundamental type. This PR attempts to resolve this potential blocker by replacing the implementation with a more general alternative. An internal trait `IoHandle` has been added which types can implement to opt-in to `Read`/`Write`/`Seek` implementations for `Arc<Self>` as long as `&Self` implements said trait. Note that `BufRead` is excluded as the signature for `fill_buf` would require returning from a temporary. Since this "blanket" implementation only applies to a single type which already implements the same traits, I believe this should have no user-facing impact. If this PR was merged, #134190 could be replaced with a 2 line PR: ```rust impl IoHandle for TcpStream {} impl IoHandle for UnixStream {} ``` Likewise for any other types, a table of which can be found [here](rust-lang/libs-team#504 (comment)). This is out of scope for this PR to avoid the need for an ACP. --- ## Notes * See [this comment](#154046 (comment)) for further details. * No AI tooling of any kind was used during the creation of this PR.
ACP: rust-lang/libs-team#755
Tracking issue: #154046
Related: #94744
Description
After experimenting with #155625, I noticed
SeekandSeekFromcan almost be moved tocore::io. Unfortunately, the implementation ofSeekforArc<File>is a blocker for such a move, sinceArcis not a fundamental type. This PR attempts to resolve this potential blocker by replacing the implementation with a more general alternative. An internal traitIoHandlehas been added which types can implement to opt-in toRead/Write/Seekimplementations forArc<Self>as long as&Selfimplements said trait. Note thatBufReadis excluded as the signature forfill_bufwould require returning from a temporary.Since this "blanket" implementation only applies to a single type which already implements the same traits, I believe this should have no user-facing impact.
If this PR was merged, #134190 could be replaced with a 2 line PR:
Likewise for any other types, a table of which can be found here. This is out of scope for this PR to avoid the need for an ACP.
Notes