extern crate cfg_if;

use std::fs::Metadata;

cfg_if::cfg_if! {
    if #[cfg(target_os = "linux")] {
        use std::os::linux::fs::MetadataExt;
    } else if #[cfg(target_os = "macos")] {
        use std::os::macos::fs::MetadataExt;
    } else {
        use std::os::redox::fs::MetadataExt;
    }
}

#[derive(Hash, Eq, PartialEq, Debug, Copy, Clone)]
pub struct FileDescriptor {
    pub dev: DeviceDescriptor,
    ino: u64,
}

#[derive(Hash, Eq, PartialEq, Debug, Copy, Clone)]
pub struct DeviceDescriptor(u64);

impl FileDescriptor {
    pub fn from_metadata(metadata: Metadata) -> FileDescriptor {
        let dev = DeviceDescriptor(metadata.st_dev());
        let ino = metadata.st_ino();

        FileDescriptor { dev, ino }
    }
}
