Skip to content

Commit

Permalink
Use the cfg-if crate for platform support conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
xen0n authored and soc committed May 11, 2019
1 parent 7341389 commit 169a953
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ repository = "https://github.com/soc/dirs-rs"
maintenance = { status = "actively-developed" }
keywords = ["xdg", "basedir", "app_dirs", "path", "folder"]

[dependencies]
cfg-if = "0.1"

[target.'cfg(unix)'.dependencies]
libc = "0.2"

Expand Down
29 changes: 20 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,29 @@
#![deny(missing_docs)]

#[macro_use]
extern crate cfg_if;

use std::path::PathBuf;

#[cfg(target_os = "windows")] mod win;
#[cfg(target_os = "macos")] mod mac;
#[cfg(target_os = "redox")] mod redox;
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "redox")))] mod lin;
#[cfg(unix)] mod unix;
#[cfg(unix)]
mod unix;

#[cfg(target_os = "windows")] use win as sys;
#[cfg(target_os = "macos")] use mac as sys;
#[cfg(target_os = "redox")] use redox as sys;
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "redox")))] use lin as sys;
cfg_if! {
if #[cfg(target_os = "windows")] {
mod win;
use win as sys;
} else if #[cfg(target_os = "macos")] {
mod mac;
use mac as sys;
} else if #[cfg(target_os = "redox")] {
mod redox;
use redox as sys;
} else {
mod lin;
use lin as sys;
}
}

/// Returns the path to the user's home directory.
///
Expand Down

0 comments on commit 169a953

Please sign in to comment.