Implement convert functions for RGB(A)

This commit is contained in:
Jaby
2022-09-22 21:18:01 +02:00
committed by Jaby
parent ad1d8e26f2
commit 3906d9649a
4 changed files with 99 additions and 33 deletions

View File

@@ -22,6 +22,10 @@ impl Error {
Error::from_text(error.to_string())
}
pub fn from_callback<F>(callback: F) -> Error where F: Fn() -> String {
Error::from_text(callback())
}
pub fn not_implemented(function: &str) -> Error {
Error::from_text(format!("{} not implemented yet", function))
}
@@ -38,7 +42,7 @@ impl Error {
}
pub fn ok_or_new<T, F>(option: Option<T>, error_text: F) -> Result<T, Error> where F: Fn () -> String{
Ok(option.ok_or(Error{exit_code: Self::DEFAULT_EXITCODE, action: String::new(), text: error_text()})?)
Ok(option.ok_or(Error::from_callback(error_text))?)
}
}