translations: Make the code cleaner
This commit is contained in:
@ -70,12 +70,12 @@ pub enum Level {
|
||||
/// Approach 2.
|
||||
pub trait Warn {
|
||||
type Value;
|
||||
fn ok_warn(self, msg: &str) -> Option<Self::Value>;
|
||||
fn or_warn(self, msg: &str) -> Option<Self::Value>;
|
||||
}
|
||||
|
||||
impl<T, E: Error> Warn for Result<T, E> {
|
||||
type Value = T;
|
||||
fn ok_warn(self, msg: &str) -> Option<T> {
|
||||
fn or_warn(self, msg: &str) -> Option<T> {
|
||||
self.map_err(|e| {
|
||||
eprintln!("{}: {}", msg, e);
|
||||
e
|
||||
@ -83,6 +83,16 @@ impl<T, E: Error> Warn for Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Warn for Option<T> {
|
||||
type Value = T;
|
||||
fn or_warn(self, msg: &str) -> Option<T> {
|
||||
self.or_else(|| {
|
||||
eprintln!("{}", msg);
|
||||
None
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A mutable handler for text warnings.
|
||||
/// Approach 3.
|
||||
pub trait WarningHandler {
|
||||
|
||||
Reference in New Issue
Block a user