Allowing an extraction of the underlying OS representation from an immutable reference seems like a violation of Rust’s mutability rules.
For example, consider giving an immutable reference to a
std::fs::File handle so that it can extract some metadata or get the path to the file (both do not require a mutable reference). That code, however, can use
libc::write on the raw fd/handle and mutate the file even though the caller may not intend extending that ability.
Are there any use cases that require access to the underlying fd/handle via immutable handle? I didn’t find much in the compiler/stdlibs but do any external libraries depend on this?
If there aren’t any explicit use cases, perhaps these traits should be changed to require a mutable receiver which would better reflect the implications of using them.