-
Notifications
You must be signed in to change notification settings - Fork 677
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
Make Flock implement AsRawFd #2571
Comments
Could you please show me more code? Specifically, the code that requires you to do these shenanigans? And, yeah, we can impl AsRawFd for Flock using |
2 code samples:
|
Only &file implements AsRawHandle on Windows and if I deref file I get a &&file which doesn't impl AsRawFd. |
use std::{fs::File, os::fd::AsRawFd};
use nix::fcntl::{Flock, FlockArg};
fn foo<FD: AsRawFd>(_: FD) {}
fn main() {
let file = File::open("Cargo.toml").unwrap();
let lock_guard = Flock::lock(file, FlockArg::LockExclusive).unwrap();
foo(lock_guard); // Error: the trait bound `Flock<File>: AsRawFd` is not satisfied
} Thanks for providing more code, I guess you are basically doing the above thing.
Could you do conditional compilation here? |
But there is indeed one thing that makes me think we can implement it, the only trait bound of |
You can, I already checked. I can PR if needed. |
Gentle ping on @asomers, thoughts on this? Is implementing AsRawFd for Flock semantically right in your opinion? |
The fact that we can already do |
Makes sense, thanks for being here. I am gonna close this issue because this feature request
|
Hello. I'm currently trying to put a flock inside a mmap, and as it doesn't implement AsRawFd, memmap2 doesn't allow it. I have to do these shenanigans:
let mut file = unsafe { File::from_raw_fd(Flock::lock(file, FlockArg::LockExclusive).ok()?.as_raw_fd()) }; // SAFETY: Raw FD is copied from an existing file
Could AsRawFd be implemented into Flock?
Thank you,
Alex <3
The text was updated successfully, but these errors were encountered: