WIP: image processing library (or libraries?) #12

Draft
schrottkatze wants to merge 15 commits from schrottkatze/iowo:proc-libs into main
Showing only changes of commit 6d318aa7c9 - Show all commits

View file

@ -14,11 +14,16 @@ pub struct Config {
impl Config { impl Config {
/// Get the configs from all possible places (args, file, env...) /// Get the configs from all possible places (args, file, env...)
pub fn read(args: &CliConfigs) -> Self { pub fn read(args: &CliConfigs) -> Self {
let config = if let Some(config) = &args.config_path { // let config = if let Some(config) = &args.config_path {
schrottkatze marked this conversation as resolved Outdated

Could use Option::ok_or with Result::or_else (untested):

let config = args.config_path.as_ref().ok_or(()).or_else(|_| find_config_file());
Could use `Option::ok_or` with `Result::or_else` (untested): ```rust let config = args.config_path.as_ref().ok_or(()).or_else(|_| find_config_file()); ```

Doesn't work since find_config_file returns an owned value and the other value is unowned, if i add .as_ref() to the find_config_file call, it doesn't work either since then it's a temporary value.

Doesn't work since `find_config_file` returns an owned value and the other value is unowned, if i add `.as_ref()` to the `find_config_file` call, it doesn't work either since then it's a temporary value.

Then how about cloning it instead?

let config = args.config_path.clone().ok_or(()).or_else(|_| find_config_file());
Then how about cloning it instead? ```rust let config = args.config_path.clone().ok_or(()).or_else(|_| find_config_file()); ```

Works.

Works.
Ok(config.clone()) // Ok(config.clone())
} else { // } else {
find_config_file() // find_config_file()
}; // };
let config = args
.config_path
.clone()
.ok_or(())
.or_else(|()| find_config_file());
// try to read a maybe existing config file // try to read a maybe existing config file
let config = config.ok().and_then(|path| { let config = config.ok().and_then(|path| {