Move stdext to ext::try_err

This commit is contained in:
2022-05-13 12:25:32 +08:00
parent 234fd90580
commit 3868d69d23
6 changed files with 4 additions and 4 deletions

View File

@@ -4,4 +4,5 @@ pub mod flagset;
pub mod json;
#[cfg(any(feature = "exif", feature = "avdict", feature = "ugoira"))]
pub mod rawhandle;
pub mod try_err;
pub mod use_or_not;

14
src/ext/try_err.rs Normal file
View File

@@ -0,0 +1,14 @@
/// Try with custom error message
pub trait TryErr<T, E> {
/// try with custom error message
fn try_err(&self, err: E) -> Result<T, E>;
}
impl<T: ToOwned + ToOwned<Owned = T>, E> TryErr<T, E> for Option<T> {
fn try_err(&self, v: E) -> Result<T, E> {
match self {
Some(r) => { Ok(r.to_owned()) }
None => { Err(v) }
}
}
}

View File

@@ -1,7 +1,7 @@
use crate::ext::json::FromJson;
use crate::ext::json::ToJson;
use crate::gettext;
use crate::stdext::TryErr;
use crate::ext::try_err::TryErr;
use std::str::FromStr;
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]