util: Include Result logger
This commit is contained in:
17
src/style.rs
17
src/style.rs
@ -21,6 +21,7 @@
|
||||
use std::env;
|
||||
|
||||
use glib::object::ObjectExt;
|
||||
use util::Warn;
|
||||
|
||||
/// Gathers stuff defined in C or called by C
|
||||
pub mod c {
|
||||
@ -61,22 +62,6 @@ pub mod c {
|
||||
// not Adwaita, but rather fall back to default
|
||||
const DEFAULT_THEME_NAME: &str = "";
|
||||
|
||||
/// Sugar for logging errors in results
|
||||
trait Warn {
|
||||
type Value;
|
||||
fn ok_warn(self, msg: &str) -> Option<Self::Value>;
|
||||
}
|
||||
|
||||
impl<T, E: std::error::Error> Warn for Result<T, E> {
|
||||
type Value = T;
|
||||
fn ok_warn(self, msg: &str) -> Option<T> {
|
||||
self.map_err(|e| {
|
||||
eprintln!("{}: {}", msg, e);
|
||||
e
|
||||
}).ok()
|
||||
}
|
||||
}
|
||||
|
||||
struct GtkTheme {
|
||||
name: String,
|
||||
variant: Option<String>,
|
||||
|
||||
16
src/util.rs
16
src/util.rs
@ -177,6 +177,22 @@ impl<T> Borrow<Rc<T>> for Pointer<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sugar for logging errors in results
|
||||
pub trait Warn {
|
||||
type Value;
|
||||
fn ok_warn(self, msg: &str) -> Option<Self::Value>;
|
||||
}
|
||||
|
||||
impl<T, E: std::error::Error> Warn for Result<T, E> {
|
||||
type Value = T;
|
||||
fn ok_warn(self, msg: &str) -> Option<T> {
|
||||
self.map_err(|e| {
|
||||
eprintln!("{}: {}", msg, e);
|
||||
e
|
||||
}).ok()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WarningHandler {
|
||||
/// Handle a warning
|
||||
fn handle(&mut self, warning: &str);
|
||||
|
||||
Reference in New Issue
Block a user