-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
OptionExt::contains
instead of local option_contains
function
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
extern crate option_ext; | ||
|
||
use std::ffi::OsString; | ||
use std::path::PathBuf; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ use std::os::unix::ffi::OsStringExt; | |
use std::path::{Path, PathBuf}; | ||
use std::str; | ||
|
||
use option_ext::OptionExt; | ||
|
||
/// Returns all XDG user directories obtained from $(XDG_CONFIG_HOME)/user-dirs.dirs. | ||
pub fn all(home_dir_path: &Path, user_dir_file_path: &Path) -> HashMap<String, PathBuf> { | ||
let bytes = read_all(user_dir_file_path).unwrap_or(Vec::new()); | ||
|
@@ -32,7 +34,7 @@ fn parse_user_dirs(home_dir: &Path, user_dir: Option<&str>, bytes: &[u8]) -> Has | |
let key = if key.starts_with(b"XDG_") && key.ends_with(b"_DIR") { | ||
match str::from_utf8(&key[4..key.len()-4]) { | ||
Ok(key) => | ||
if user_dir.is_some() && option_contains(user_dir, key) { | ||
if user_dir.contains(&key) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
fujiapple852
|
||
single_dir_found = true; | ||
key | ||
} else if user_dir.is_none() { | ||
|
@@ -137,18 +139,12 @@ fn shell_unescape(escaped: &[u8]) -> Vec<u8> { | |
unescaped | ||
} | ||
|
||
fn option_contains<T : PartialEq>(option: Option<T>, value: T) -> bool { | ||
match option { | ||
Some(val) => val == value, | ||
None => false | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::collections::HashMap; | ||
use std::path::{Path, PathBuf}; | ||
use super::{trim_blank, shell_unescape, split_once, parse_user_dirs}; | ||
|
||
use super::{parse_user_dirs, shell_unescape, split_once, trim_blank}; | ||
|
||
#[test] | ||
fn test_trim_blank() { | ||
|
Why not just use
if user_dir == Some(key)
here?