[fractal] Switch from failure to anyhow



commit e4ca9dc5c0f4401f350338e4cd9b0734db9371bf
Author: Yuki Okushi <huyuumi dev gmail com>
Date:   Thu Aug 13 14:41:50 2020 +0900

    Switch from failure to anyhow

 Cargo.lock                      | 8 +++++++-
 fractal-gtk/Cargo.toml          | 2 +-
 fractal-gtk/src/appop/attach.rs | 2 +-
 fractal-gtk/src/cache/mod.rs    | 2 +-
 fractal-gtk/src/cache/state.rs  | 7 +++----
 fractal-gtk/src/util.rs         | 8 ++++----
 6 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index c0b5e5e2..f26d9787 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -88,6 +88,12 @@ dependencies = [
  "winapi 0.3.9",
 ]
 
+[[package]]
+name = "anyhow"
+version = "1.0.32"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
+
 [[package]]
 name = "arrayref"
 version = "0.3.6"
@@ -580,6 +586,7 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
 name = "fractal-gtk"
 version = "4.4.0"
 dependencies = [
+ "anyhow",
  "cairo-rs",
  "chrono",
  "clap",
@@ -587,7 +594,6 @@ dependencies = [
  "directories",
  "dirs",
  "either 1.5.99",
- "failure",
  "fractal-matrix-api",
  "fragile",
  "gdk",
diff --git a/fractal-gtk/Cargo.toml b/fractal-gtk/Cargo.toml
index 960f64b5..e1c6a33d 100644
--- a/fractal-gtk/Cargo.toml
+++ b/fractal-gtk/Cargo.toml
@@ -6,11 +6,11 @@ workspace = "../"
 edition = "2018"
 
 [dependencies]
+anyhow = "1.0.32"
 clap = "2.33.0"
 comrak = "0.7.0"
 directories = "2.0.2"
 dirs = "2.0.2"
-failure = "0.1.6"
 fragile = "1.0.0"
 gspell = "0.4.0"
 gdk = "0.12.1"
diff --git a/fractal-gtk/src/appop/attach.rs b/fractal-gtk/src/appop/attach.rs
index 3f0813aa..3b5bff4c 100644
--- a/fractal-gtk/src/appop/attach.rs
+++ b/fractal-gtk/src/appop/attach.rs
@@ -6,7 +6,7 @@ use std::io::prelude::*;
 use std::path::PathBuf;
 use std::sync::{Arc, Mutex};
 
-use failure::Error;
+use anyhow::Error;
 
 use gtk::prelude::*;
 
diff --git a/fractal-gtk/src/cache/mod.rs b/fractal-gtk/src/cache/mod.rs
index 76942866..8943eac6 100644
--- a/fractal-gtk/src/cache/mod.rs
+++ b/fractal-gtk/src/cache/mod.rs
@@ -12,7 +12,7 @@ use std::thread;
 
 use crate::types::Room;
 use crate::types::RoomList;
-use failure::Error;
+use anyhow::Error;
 use fractal_api::identifiers::{DeviceId, UserId};
 use std::collections::HashMap;
 use std::hash::Hash;
diff --git a/fractal-gtk/src/cache/state.rs b/fractal-gtk/src/cache/state.rs
index 7cb5372a..0e62c59b 100644
--- a/fractal-gtk/src/cache/state.rs
+++ b/fractal-gtk/src/cache/state.rs
@@ -4,8 +4,7 @@ use mdl::Model;
 use mdl::Store;
 use serde::{Deserialize, Serialize};
 
-use failure::err_msg;
-use failure::Error;
+use anyhow::{anyhow, Error};
 
 use std::cell::RefCell;
 use std::fs::remove_dir_all;
@@ -127,8 +126,8 @@ impl FCache {
         guard.take();
 
         let fname = cache_dir_path(None, "cache.mdl")
-            .or_else(|_| Err(err_msg("Can't remove cache file")))?;
-        remove_dir_all(fname).or_else(|_| Err(err_msg("Can't remove cache file")))
+            .or_else(|_| Err(anyhow!("Can't remove cache file")))?;
+        remove_dir_all(fname).or_else(|_| Err(anyhow!("Can't remove cache file")))
     }
 
     #[allow(dead_code)]
diff --git a/fractal-gtk/src/util.rs b/fractal-gtk/src/util.rs
index 764a8e8e..b2feb12c 100644
--- a/fractal-gtk/src/util.rs
+++ b/fractal-gtk/src/util.rs
@@ -1,6 +1,6 @@
 use crate::globals::CACHE_PATH;
-use failure::format_err;
-use failure::Error as FailError;
+use anyhow::anyhow;
+use anyhow::Error as AnyhowError;
 use gdk::prelude::*;
 use gdk_pixbuf::Pixbuf;
 use gio::{Settings, SettingsExt, SettingsSchemaSource};
@@ -21,9 +21,9 @@ pub fn cache_dir_path(dir: Option<&str>, name: &str) -> Result<PathBuf, IoError>
     Ok(path.join(name))
 }
 
-pub fn get_pixbuf_data(pb: &Pixbuf) -> Result<Vec<u8>, FailError> {
+pub fn get_pixbuf_data(pb: &Pixbuf) -> Result<Vec<u8>, AnyhowError> {
     let image = cairo::ImageSurface::create(cairo::Format::ARgb32, pb.get_width(), pb.get_height())
-        .or_else(|_| Err(format_err!("Cairo Error")))?;
+        .or_else(|_| Err(anyhow!("Cairo Error")))?;
 
     let g = cairo::Context::new(&image);
     g.set_source_pixbuf(pb, 0.0, 0.0);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]