Why are Linux file descriptors and Windows file handles are considered different things by a standard library?

Hello everyone!

I've noticed that the Rust standard library distinguishes concepts of Unix file descriptor and Windows file handle. However, as far as I understand, both can serve either as a reference to the open file that can be used for I/O or other manipulation, or a reference to some other object for some other tasks, and Rust standard library interface to them look similar. I wonder, what is the reason for such distinction?

Only conceptually. Implementation-wise: most of the OS-specific details are going to be completely different. In the world of Unix, "everything a file". In Win32, every "handle" may require to be "handled" according to its own set of rules and protocols. Mixing them up for the sake of convenience and/or uniformity, although somewhat more practical on a surface level, would be a recipe for disaster.

5 Likes

The most critical difference is that windows sockets are different, so AsHandle wouldn't be appropriate for TcpStream.

3 Likes

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.