Replacing a function from the standard library

Context

In my application, I'm presently using std::fs::copy to copy some files. The underlying implementations of this function for the platforms I'm interested in call out to the private function open_to_and_set_permissions. I would like to make a slight modification to open_to_and_set_permissions for the sake of avoiding additional syscalls which happen to be unnecessary for my use-case in a particularly performance-critical portion of my application.

Core issue

Is there any way to replace the implementation of a single private function from the standard library (in this case open_to_and_set_permissions)? I realize that I could solve my problem by literally copy-pasting the definitions of all of the relevant functions into my own crate, and calling those functions instead, but I'd like to avoid resorting to that if at all possible.

No, it is not possible to replace a single function without changing the source and recompiling. It might have been inlined in the already existing compiled objects. For the standard library recompiling needs a nightly rustc.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.