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

tokio::fs::write clones the data #7183

Open
oriongonza opened this issue Feb 27, 2025 · 3 comments
Open

tokio::fs::write clones the data #7183

oriongonza opened this issue Feb 27, 2025 · 3 comments
Labels
A-tokio Area: The main tokio crate M-fs Module: tokio/fs

Comments

@oriongonza
Copy link

I get that it's supposed to be a 1 <-> 1 with std::fs::write but it copies whatever you give it and it doesn't even tell you about it until you look at the source code.

A better interface might be something like AsRef<[u8]> + Send + 'static so that you can pass owned data like Vec<u8>, Arc<[u8]>, bytes::Bytes...

However this is a breaking change as &[u8] could no longer be sent.

So either a new API for this or comment clearly that this will clone the data.

@maminrayej maminrayej added A-tokio Area: The main tokio crate M-fs Module: tokio/fs labels Feb 27, 2025
@Darksonn
Copy link
Contributor

I've looked into this before, and it cannot be fixed, unfortunately.

Happy to see additional docs about this.

@oriongonza
Copy link
Author

What about adding another function and deprecating this?

@paolobarbolini
Copy link
Contributor

I may have found a solution in #7199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-fs Module: tokio/fs
Projects
None yet
Development

No branches or pull requests

4 participants