Closed ids1024 closed 1 year ago
Looking at the implementation, it seems that RawFd
is the correct type here.
The fd is used to map the file to memory, and the map is dropped by when the function returns.
So the Keymap
doesn't keep any reference to the file whatsoever.
it seems that RawFd is the correct type here
In fact, no. Your PR is correct.
File::from_raw_fd
consumes the descriptor, and closes it just after the memory is mapped.
This is a breaking API change and requires Rust 1.63.
The function still needs to be
unsafe
since the fd is mmaped, but this is more idiomatic and makes it clear that the file descriptor is owned rather than borrowed. (Which should match the existing implementation). Though maybe it should only borrow the FD?It wasn't documented explicitly if this took ownership of the fd, and this wasn't handled correctly in smithay-client-toolkit: https://github.com/Smithay/client-toolkit/pull/412.