Closed vlovich closed 3 years ago
This api is completely universal, and implementing your own File versions is easy.
The only thing is that there will be a different description for Windows.
For example linux:
impl FlockElement for async_std::fs::File {
type FilePtr = async_std::os::unix::io::RawFd;
#[inline(always)]
fn as_file_ptr(&self) -> Self::FilePtr {
async_std::os::unix::io::AsRawFd::as_raw_fd(self)
}
}
Why is it so easy?
AsRawFd trait for async file is PRESENT (>>> https://docs.rs/async-std/1.7.0/async_std/fs/struct.File.html#impl-AsRawFd)
source 0: https://docs.rs/async-std/1.7.0/async_std/fs/struct.File.html#impl-AsRawFd source 1: https://docs.rs/crate/cluFlock/1.2.5/source/src/os_release/unix.rs
// 1. Whether this will work without proper async support I'm not sure yet. // 2. It also begs the question why the async devs didn't take https://doc.rust-lang.org/std/os/unix/io/type.RawFd.html ... // 3. I wrote it without actually checking it, I just don't have time.
After implementing this trait, all Api calls will work the same as with a regular file, another question is whether these system calls will work.
Thanks!
If I have an
async_std::fs::File
object, how do I use this API to acquire a lock? It seems like it operates on the actualstd::fs::File
object rather than onAsRawFd
/AsRawHandle
traits?