Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Read and Write access through Arc<T> if &T: Read/Write #53835

Closed
jonhoo opened this issue Aug 30, 2018 · 1 comment
Closed

Provide Read and Write access through Arc<T> if &T: Read/Write #53835

jonhoo opened this issue Aug 30, 2018 · 1 comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Aug 30, 2018

Some types (net:TcpStream and fs:File in particular) implement io::Read and io::Write on &'a T. If one of these types are wrapped in an Arc (or Rc), there is no real reason why one shouldn't be able to call Read or Write methods on it. For example, this code should compile:

let mut x = Arc::new(TcpStream::connect("127.0.0.1:80")?);
x.read(&mut [0; 32])?;

I think this can be implemented pretty straightforwardly by adding the following impls to Arc and Rc:

impl<'a, T> io::Read for Arc<T> where &'a T: io::Read { .. }
impl<'a, T> io::Write for Arc<T> where &'a T: io::Write { .. }

Are there good reasons for why impls like these shouldn't be added?

@memoryruins memoryruins added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Sep 15, 2018
tbu- added a commit to tbu-/rust that referenced this issue Mar 8, 2022
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.
@dtolnay
Copy link
Member

dtolnay commented Mar 8, 2022

Closing because generic impls like proposed won't behave correctly, as described in #94744.

@dtolnay dtolnay closed this as completed Mar 8, 2022
tbu- added a commit to tbu-/rust that referenced this issue Jun 23, 2023
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.
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Jun 27, 2023
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.
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 10, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants