#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct IoPrimitives {
pub io_uring: bool,
pub iocp: bool,
pub kqueue: bool,
pub nvme_passthrough: bool,
pub direct_io: bool,
pub mmap: bool,
}
#[must_use]
pub(super) fn probe() -> IoPrimitives {
super::probe::platform::probe_io_primitives()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_has_all_fields_false() {
let p = IoPrimitives::default();
assert!(!p.io_uring);
assert!(!p.iocp);
assert!(!p.kqueue);
assert!(!p.nvme_passthrough);
assert!(!p.direct_io);
assert!(!p.mmap);
}
#[test]
fn test_probe_reports_iocp_only_on_windows() {
let p = probe();
if cfg!(target_os = "windows") {
assert!(p.iocp);
} else {
assert!(!p.iocp);
}
}
#[test]
fn test_probe_reports_kqueue_on_bsds_and_macos() {
let p = probe();
let expected = cfg!(any(
target_os = "macos",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "dragonfly",
));
assert_eq!(p.kqueue, expected);
}
#[test]
fn test_probe_reports_mmap_on_supported_targets() {
let p = probe();
if cfg!(any(unix, windows)) {
assert!(p.mmap);
}
}
#[test]
fn test_probe_io_uring_runtime_check_does_not_panic() {
let p = probe();
if !cfg!(target_os = "linux") {
assert!(!p.io_uring);
}
}
#[test]
fn test_probe_does_not_lie_about_nvme_passthrough_in_0_5_0() {
assert!(!probe().nvme_passthrough);
}
}