1 use std::fs::File;
2 use std::io::Read;
3 use std::path::Path;
4 
5 use crate::error::Result;
6 
load_yaml_file(path: &Path) -> Result<String>7 pub fn load_yaml_file(path: &Path) -> Result<String> {
8     let mut file = File::open(path)?;
9     let mut contents = String::new();
10     file.read_to_string(&mut contents)?;
11     Ok(contents)
12 }
13 
14 /// Helper function that might appear in Rust stable at some point
15 /// (https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.transpose)
transpose<T, E>( opt: Option<std::result::Result<T, E>>, ) -> std::result::Result<Option<T>, E>16 pub fn transpose<T, E>(
17     opt: Option<std::result::Result<T, E>>,
18 ) -> std::result::Result<Option<T>, E> {
19     opt.map_or(Ok(None), |res| res.map(Some))
20 }
21 
get_first_existing_path<'a>(paths: &[&'a Path]) -> Option<&'a Path>22 pub fn get_first_existing_path<'a>(paths: &[&'a Path]) -> Option<&'a Path> {
23     paths.iter().find(|p| Path::exists(*p)).copied()
24 }
25 
get_all_existing_paths<'a>(paths: &[&'a Path]) -> Vec<&'a Path>26 pub fn get_all_existing_paths<'a>(paths: &[&'a Path]) -> Vec<&'a Path> {
27     paths.iter().cloned().filter(|p| Path::exists(*p)).collect()
28 }
29