From 7c53ecd4c2862cfcf50ee03ab1ab64a8d2448fab Mon Sep 17 00:00:00 2001 From: Wang Xuerui Date: Sat, 11 May 2019 18:59:48 +0800 Subject: [PATCH] Rustfmt --- src/lib.rs | 1 - src/unix.rs | 37 ++++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5ad08fa..762e0e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -254,7 +254,6 @@ pub fn video_dir() -> Option { sys::video_dir() } - #[cfg(test)] mod tests { #[test] diff --git a/src/unix.rs b/src/unix.rs index 3b16b06..9068ed7 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -1,28 +1,27 @@ #![cfg(unix)] use std::env; -use std::path::PathBuf; -use std::mem; -use std::ptr; use std::ffi::CStr; use std::ffi::OsString; +use std::mem; use std::os::unix::ffi::OsStringExt; +use std::path::PathBuf; +use std::ptr; extern crate libc; // https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/os.rs#L498 pub fn home_dir() -> Option { - return env::var_os("HOME").and_then(|h| { if h.is_empty() { None } else { Some(h) } } ).or_else(|| unsafe { - fallback() - }).map(PathBuf::from); + return env::var_os("HOME") + .and_then(|h| if h.is_empty() { None } else { Some(h) }) + .or_else(|| unsafe { fallback() }) + .map(PathBuf::from); - #[cfg(any(target_os = "android", - target_os = "ios", - target_os = "emscripten"))] - unsafe fn fallback() -> Option { None } - #[cfg(not(any(target_os = "android", - target_os = "ios", - target_os = "emscripten")))] + #[cfg(any(target_os = "android", target_os = "ios", target_os = "emscripten"))] + unsafe fn fallback() -> Option { + None + } + #[cfg(not(any(target_os = "android", target_os = "ios", target_os = "emscripten")))] unsafe fn fallback() -> Option { let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { n if n < 0 => 512 as usize, @@ -31,8 +30,13 @@ pub fn home_dir() -> Option { let mut buf = Vec::with_capacity(amt); let mut passwd: libc::passwd = mem::zeroed(); let mut result = ptr::null_mut(); - match libc::getpwuid_r(libc::getuid(), &mut passwd, buf.as_mut_ptr(), - buf.capacity(), &mut result) { + match libc::getpwuid_r( + libc::getuid(), + &mut passwd, + buf.as_mut_ptr(), + buf.capacity(), + &mut result, + ) { 0 if !result.is_null() => { let ptr = passwd.pw_dir as *const _; let bytes = CStr::from_ptr(ptr).to_bytes(); @@ -41,9 +45,8 @@ pub fn home_dir() -> Option { } else { Some(OsStringExt::from_vec(bytes.to_vec())) } - }, + } _ => None, } } } -