pub fn default_path() -> io::Result<PathBuf> {
        let hosts_file = if cfg!(unix) {
            PathBuf::from("/etc/hosts")
        } else if cfg!(windows) {
            PathBuf::from(
                // according to https://support.microsoft.com/en-us/topic/how-to-reset-the-hosts-file-back-to-the-default-c2a43f9d-e176-c6f3-e4ef-3500277a6dae
                // the location depends on the environment variable %WinDir%.
                format!(
                    "{}\\System32\\Drivers\\Etc\\hosts",
                    std::env::var("WinDir").map_err(|_| io::Error::new(
                        ErrorKind::Other,
                        "WinDir environment variable missing".to_owned()
                    ))?
                ),
            )
        } else {
            return Err(io::Error::new(
                ErrorKind::Other,
                "unsupported operating system.".to_owned(),
            ));
        };

        if !hosts_file.exists() {
            return Err(ErrorKind::NotFound.into());
        }

        Ok(hosts_file)
    }
/// Returns the default hosts path based on the current OS.
Returns the default hosts path based on the current OS.
Returns the default hosts path based on the current OS .
pub fn default_path() -> io::Result<PathBuf> {
        let hosts_file = if cfg!(unix) {
            PathBuf::from("/etc/hosts")
        } else if cfg!(windows) {
            PathBuf::from(
                // according to https://support.microsoft.com/en-us/topic/how-to-reset-the-hosts-file-back-to-the-default-c2a43f9d-e176-c6f3-e4ef-3500277a6dae
                // the location depends on the environment variable %WinDir%.
                format!(
                    "{}\\System32\\Drivers\\Etc\\hosts",
                    std::env::var("WinDir").map_err(|_| io::Error::new(
                        ErrorKind::Other,
                        "WinDir environment variable missing".to_owned()
                    ))?
                ),
            )
        } else {
            return Err(io::Error::new(
                ErrorKind::Other,
                "unsupported operating system.".to_owned(),
            ));
        };
        if !hosts_file.exists() {
            return Err(ErrorKind::NotFound.into());
        }
        Ok(hosts_file)
    }
pub fn default_path ( ) -> io :: Result < PathBuf > { let hosts_file = if cfg ! ( unix ) { PathBuf :: from ( " " ) } else if cfg ! ( windows ) { PathBuf :: from ( // according to https://support.microsoft.com/en-us/topic/how-to-reset-the-hosts-file-back-to-the-default-c2a43f9d-e176-c6f3-e4ef-3500277a6dae // the location depends on the environment variable %WinDir%. format ! ( " \\ \\ \\ \\ " std env var ( " " ) map_err ( io Error new ( ErrorKind Other " " to_owned ( ) ) ) ) , ) } else { return Err ( io :: Error :: new ( ErrorKind :: Other , " " . to_owned ( ) , ) ) ; } ; if ! hosts_file . exists ( ) { return Err ( ErrorKind :: NotFound . into ( ) ) ; } Ok ( hosts_file ) }
Returns the default hosts path based on the current OS.
Returns the default hosts path based on the current OS .