veilid-tools 0.5.6

A collection of baseline tools for Rust development use by Veilid and Veilid-enabled Rust applications
Documentation
use cfg_if::*;
use std::path::Path;

cfg_if! {
    if #[cfg(feature="rt-tokio")] {
        mod ipc_tokio;
        pub use ipc_tokio::*;
    } else if #[cfg(feature="rt-async-std")] {
        mod ipc_async_std;
        #[cfg_attr(windows, allow(unused_imports))]
        pub use ipc_async_std::*;
    }
}

/// Whether `path` refers to an existing IPC endpoint: a named pipe on Windows,
/// a unix domain socket elsewhere. Always `false` on unsupported platforms.
#[allow(unused_variables)]
pub fn is_ipc_socket_path<P: AsRef<Path>>(path: P) -> bool {
    cfg_if! {
        if #[cfg(windows)] {
            let p = path.as_ref().to_path_buf().to_string_lossy().to_string().to_lowercase();
            p.starts_with(r"\\.\pipe") && path.as_ref().exists()
        } else if #[cfg(unix)] {
            use std::os::unix::fs::FileTypeExt;
            let meta = match std::fs::metadata(path) {
                Ok(v) => v,
                Err(_) => {
                    return false;
                }
            };
            meta.file_type().is_socket()
        } else {
            false
        }
    }
}