mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Move stdext to ext::try_err
This commit is contained in:
@@ -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
14
src/ext/try_err.rs
Normal 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) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user