1use std::os::fd::{AsRawFd, OwnedFd, RawFd};
2use std::os::unix::ffi::OsStrExt;
3use std::sync::Arc;
4use std::{ffi::CString, io, path::Path};
5
6pub(crate) type ArcFd = Arc<dyn AsRawFd + Send + Sync + 'static>;
7
8pub(crate) trait UringFd: Send + Sync + 'static {
14 fn as_raw_fd(&self) -> RawFd;
15}
16
17impl UringFd for OwnedFd {
18 fn as_raw_fd(&self) -> RawFd {
19 AsRawFd::as_raw_fd(self)
20 }
21}
22
23impl UringFd for ArcFd {
24 fn as_raw_fd(&self) -> RawFd {
25 (**self).as_raw_fd()
26 }
27}
28
29pub(crate) fn cstr(p: &Path) -> io::Result<CString> {
30 Ok(CString::new(p.as_os_str().as_bytes())?)
31}