-
Notifications
You must be signed in to change notification settings - Fork 13.4k
It's not possible to open a file without invoking allocations for the file name #22190
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
Comments
It is pretty hard to not involve allocations because Rust-native strings will have to be converted into null terminated one to pass into the native API at some point anyway. |
That's true.. Maybe we can avoid the double-allocation? |
@tbu- The path is cloned only so that it can later be used in error messages, which is a somewhat debatable use case. We could resolve this in the future by taking an |
@aturon In that case it would probably be better to just take a PathBuf. But does it really justify an extra allocation just to provide error messages? |
That would be a lot less ergonomic -- I want to be able to feed in a string literal with no extra steps.
Probably not, hence why I said it was a "somewhat debatable use case." :) |
@nagisa What about a variable-length stack allocation? |
@alexchandel allocating on stack comes with its own downsides. Also, it doesn’t guarantee a trailing null byte either, AFAIK? |
@nagisa If you had a stack allocation, you could just append a null byte. |
@nagisa As tbu- said. And the downsides of |
File::open
takes aPath
object as reference, although it only clones it afterwards.It's also impossible to re-use the allocation for the file path, because it's only dropped at the end.
The text was updated successfully, but these errors were encountered: