Add Read, Write and Seek impls for Arc<T> where appropriate#94744
Add Read, Write and Seek impls for Arc<T> where appropriate#94744tbu- wants to merge 1 commit intorust-lang:masterfrom
Read, Write and Seek impls for Arc<T> where appropriate#94744Conversation
If `&T` implements these traits, `Arc<T>` has no reason not to do so either. This is useful for operating system handles like `File` or `TcpStream` which don't need a mutable reference to implement these traits. Fix rust-lang#53835.
|
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
|
This is incorrect, or at least has very surprising behaviour, if But this impl will create a new |
dtolnay
left a comment
There was a problem hiding this comment.
I was about to comment the same as @SNCPlay42. I don't think any of these impls behave correctly in general. Mutations of the &mut &R by the underlying trait impls are just thrown away.
FYI @rust-lang/libs-api @jonhoo in case anyone sees a way to rescue this.
Impls for specific types like Arc<File> can work but I'm not sure which ones make sense / are needed.
|
Oh, interesting, I hadn't though of that — good catch! In that case I'd be in favor of at least adding the impls for the concrete types we know where this would be really useful (like |
If `&T` implements these traits, `Arc<T>` has no reason not to do so either. This is useful for operating system handles like `File` or `TcpStream` which don't need a mutable reference to implement these traits. CC rust-lang#53835. CC rust-lang#94744.
Add `Read`, `Write` and `Seek` impls for `Arc<File>` where appropriate If `&T` implements these traits, `Arc<T>` has no reason not to do so either. This is useful for operating system handles like `File` or `TcpStream` which don't need a mutable reference to implement these traits. CC rust-lang#53835. CC rust-lang#94744.
Add `Read`, `Write` and `Seek` impls for `Arc<File>` where appropriate If `&T` implements these traits, `Arc<T>` has no reason not to do so either. This is useful for operating system handles like `File` or `TcpStream` which don't need a mutable reference to implement these traits. CC rust-lang#53835. CC rust-lang#94744.
…ref, r=jhpratt Generalize IO Traits for `Arc<T>` where `&T: IoTrait` ACP: rust-lang/libs-team#755 Tracking issue: rust-lang#154046 Related: rust-lang#94744 ## Description After experimenting with rust-lang#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, rust-lang#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](rust-lang#154046 (comment)) for further details. * No AI tooling of any kind was used during the creation of this PR.
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.
…pratt Generalize IO Traits for `Arc<T>` where `&T: IoTrait` ACP: rust-lang/libs-team#755 Tracking issue: rust-lang/rust#154046 Related: rust-lang/rust#94744 ## Description After experimenting with rust-lang/rust#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, rust-lang/rust#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](rust-lang/rust#154046 (comment)) for further details. * No AI tooling of any kind was used during the creation of this PR.
If
&Timplements these traits,Arc<T>has no reason not to do soeither. This is useful for operating system handles like
FileorTcpStreamwhich don't need a mutable reference to implement thesetraits.
Fix #53835.