diff --git a/Cargo.toml b/Cargo.toml index 4132e1420..6a4957b3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,9 @@ description = "A framework for making client-side single-page apps" travis-ci = { repository = "yewstack/yew" } [dependencies] +anyhow = "1" anymap = "0.12" bincode = { version = "~1.2.1", optional = true } -failure = "0.1" http = "0.2" indexmap = "1.0.2" log = "0.4" @@ -34,6 +34,7 @@ serde_json = "1.0" serde_yaml = { version = "0.8.3", optional = true } slab = "0.4" stdweb = "0.4.20" +thiserror = "1" toml = { version = "0.5", optional = true } yew-macro = { version = "0.11.1", path = "crates/macro" } diff --git a/examples/dashboard/Cargo.toml b/examples/dashboard/Cargo.toml index 8efe5b565..f4e0ddb55 100644 --- a/examples/dashboard/Cargo.toml +++ b/examples/dashboard/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Denis Kolodin "] edition = "2018" [dependencies] -failure = "0.1" +anyhow = "1" serde = "1" serde_derive = "1" yew = { path = "../..", features = ["toml"] } diff --git a/examples/dashboard/src/lib.rs b/examples/dashboard/src/lib.rs index d8dab862f..971903e4e 100644 --- a/examples/dashboard/src/lib.rs +++ b/examples/dashboard/src/lib.rs @@ -1,6 +1,6 @@ #![recursion_limit = "256"] -use failure::Error; +use anyhow::Error; use serde_derive::{Deserialize, Serialize}; use yew::format::{Json, Nothing, Toml}; use yew::services::fetch::{FetchService, FetchTask, Request, Response}; diff --git a/examples/npm_and_rest/Cargo.toml b/examples/npm_and_rest/Cargo.toml index fbe3a52a6..146b3b7a7 100644 --- a/examples/npm_and_rest/Cargo.toml +++ b/examples/npm_and_rest/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Denis Kolodin "] edition = "2018" [dependencies] -failure = "0.1" +anyhow = "1" serde = "1" serde_derive = "1" stdweb = "0.4.20" diff --git a/examples/npm_and_rest/src/gravatar.rs b/examples/npm_and_rest/src/gravatar.rs index 6b8b0401b..2dafae95a 100644 --- a/examples/npm_and_rest/src/gravatar.rs +++ b/examples/npm_and_rest/src/gravatar.rs @@ -1,4 +1,4 @@ -use failure::{format_err, Error}; +use anyhow::{anyhow, Error}; use serde_derive::Deserialize; use yew::callback::Callback; use yew::format::{Json, Nothing}; @@ -38,8 +38,7 @@ impl GravatarService { if meta.status.is_success() { callback.emit(data) } else { - // format_err! is a macro in crate `failure` - callback.emit(Err(format_err!( + callback.emit(Err(anyhow!( "{}: error getting profile https://gravatar.com/", meta.status ))) diff --git a/examples/npm_and_rest/src/lib.rs b/examples/npm_and_rest/src/lib.rs index 799ef60f3..27d646ae3 100644 --- a/examples/npm_and_rest/src/lib.rs +++ b/examples/npm_and_rest/src/lib.rs @@ -7,7 +7,7 @@ extern crate stdweb; pub mod ccxt; pub mod gravatar; -use failure::Error; +use anyhow::Error; use yew::services::fetch::FetchTask; use yew::{html, Callback, Component, ComponentLink, Html, ShouldRender}; diff --git a/src/format/macros.rs b/src/format/macros.rs index 0c39a4430..f782dfa4f 100644 --- a/src/format/macros.rs +++ b/src/format/macros.rs @@ -7,17 +7,17 @@ macro_rules! text_format { T: ::serde::Serialize, { fn into(self) -> $crate::format::Text { - $format::to_string(&self.0).map_err(::failure::Error::from) + $format::to_string(&self.0).map_err(::anyhow::Error::from) } } - impl From<$crate::format::Text> for $type> + impl From<$crate::format::Text> for $type> where T: for<'de> ::serde::Deserialize<'de>, { fn from(value: $crate::format::Text) -> Self { match value { - Ok(data) => $type($format::from_str(&data).map_err(::failure::Error::from)), + Ok(data) => $type($format::from_str(&data).map_err(::anyhow::Error::from)), Err(reason) => $type(Err(reason)), } } @@ -35,17 +35,17 @@ macro_rules! binary_format { T: ::serde::Serialize, { fn into(self) -> $crate::format::Binary { - $into(&self.0).map_err(::failure::Error::from) + $into(&self.0).map_err(::anyhow::Error::from) } } - impl From<$crate::format::Binary> for $type> + impl From<$crate::format::Binary> for $type> where T: for<'de> ::serde::Deserialize<'de>, { fn from(value: $crate::format::Binary) -> Self { match value { - Ok(data) => $type($from(&data).map_err(::failure::Error::from)), + Ok(data) => $type($from(&data).map_err(::anyhow::Error::from)), Err(reason) => $type(Err(reason)), } } @@ -57,11 +57,11 @@ macro_rules! text_format_is_an_error { ($type:ident) => { use $crate::format::FormatError; - fn to_string(_value: T) -> Result { + fn to_string(_value: T) -> Result { Err(FormatError::CantEncodeBinaryAsText.into()) } - fn from_str(_s: &str) -> Result { + fn from_str(_s: &str) -> Result { Err(FormatError::ReceivedTextForBinary.into()) } diff --git a/src/format/mod.rs b/src/format/mod.rs index 6c6583f93..a89c4b782 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -4,8 +4,8 @@ //! All types here are lazy and it's necessary to //! use `Into` and `From` traits to get (convert) the data. -use failure::Error; -use failure::Fail; +use anyhow::Error; +use thiserror::Error as ThisError; #[macro_use] pub mod macros; @@ -54,14 +54,14 @@ pub type Binary = Result, Error>; pub type Format = Result; /// Represents formatting errors. -#[derive(Debug, Fail)] +#[derive(Debug, ThisError)] pub enum FormatError { /// Received text for a binary format, e.g. someone sending text /// on a WebSocket that is using a binary serialization format, like Cbor. - #[fail(display = "received text for a binary format")] + #[error("received text for a binary format")] ReceivedTextForBinary, /// Trying to encode a binary format as text", e.g., trying to /// store a Cbor encoded value in a String. - #[fail(display = "trying to encode a binary format as Text")] + #[error("trying to encode a binary format as Text")] CantEncodeBinaryAsText, } diff --git a/src/format/nothing.rs b/src/format/nothing.rs index 01b6d5d17..88bc5fa60 100644 --- a/src/format/nothing.rs +++ b/src/format/nothing.rs @@ -1,7 +1,7 @@ //! Contains an implementation of empty serialization format (`Nothing`). use super::{Binary, Text}; -use failure::err_msg; +use anyhow::bail; /// A representation of an empty data. Nothing stored. Nothing restored. #[derive(Debug)] @@ -9,7 +9,7 @@ pub struct Nothing; impl Into for Nothing { fn into(self) -> Text { - Err(err_msg("nothing")) + bail!("nothing") } } @@ -21,7 +21,7 @@ impl From for Nothing { impl Into for Nothing { fn into(self) -> Binary { - Err(err_msg("nothing")) + bail!("nothing") } } diff --git a/src/services/fetch.rs b/src/services/fetch.rs index 49b8f2829..00f6d9007 100644 --- a/src/services/fetch.rs +++ b/src/services/fetch.rs @@ -3,7 +3,6 @@ use super::Task; use crate::callback::Callback; use crate::format::{Binary, Format, Text}; -use failure::Fail; use serde::Serialize; use std::collections::HashMap; use std::fmt; @@ -13,6 +12,7 @@ use stdweb::web::ArrayBuffer; use stdweb::{JsSerialize, Value}; #[allow(unused_imports)] use stdweb::{_js_impl, js}; +use thiserror::Error; pub use http::{HeaderMap, Method, Request, Response, StatusCode, Uri}; @@ -90,9 +90,9 @@ pub struct FetchOptions { } /// Represents errors of a fetch service. -#[derive(Debug, Fail)] +#[derive(Debug, Error)] enum FetchError { - #[fail(display = "failed response")] + #[error("failed response")] FailedResponse, } @@ -157,10 +157,10 @@ impl FetchService { ///# fn dont_execute() { ///# let link: ComponentLink = unimplemented!(); ///# let mut fetch_service: FetchService = FetchService::new(); - ///# let post_request: Request> = unimplemented!(); + ///# let post_request: Request> = unimplemented!(); /// let task = fetch_service.fetch( /// post_request, - /// link.callback(|response: Response>| { + /// link.callback(|response: Response>| { /// if response.status().is_success() { /// Msg::Noop /// } else { @@ -201,7 +201,7 @@ impl FetchService { ///# fn dont_execute() { ///# let link: ComponentLink = unimplemented!(); /// let get_request = Request::get("/thing").body(Nothing).unwrap(); - /// let callback = link.callback(|response: Response>>| { + /// let callback = link.callback(|response: Response>>| { /// if let (meta, Json(Ok(body))) = response.into_parts() { /// if meta.status.is_success() { /// return Msg::FetchResourceComplete(body); @@ -245,7 +245,7 @@ impl FetchService { ///# pub enum Msg {} ///# fn dont_execute() { ///# let link: ComponentLink = unimplemented!(); - ///# let callback = link.callback(|response: Response>| unimplemented!()); + ///# let callback = link.callback(|response: Response>| unimplemented!()); /// let request = fetch::Request::get("/path/") /// .body(Nothing) /// .unwrap(); diff --git a/src/services/storage.rs b/src/services/storage.rs index e559740a4..647542399 100644 --- a/src/services/storage.rs +++ b/src/services/storage.rs @@ -2,14 +2,14 @@ //! use local and session storage of a browser. use crate::format::Text; -use failure::Fail; use std::fmt; use stdweb::web::{window, Storage}; +use thiserror::Error; /// Represents errors of a storage. -#[derive(Debug, Fail)] +#[derive(Debug, Error)] enum StorageError { - #[fail(display = "restore error")] + #[error("restore error")] CantRestore, } diff --git a/src/utils.rs b/src/utils.rs index 9fd2ebcaf..c4f17a5af 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,6 @@ //! This module contains useful utils to get information about the current document. -use failure::{err_msg, Error}; +use anyhow::{anyhow, Error}; use std::marker::PhantomData; use stdweb::web::document; @@ -8,7 +8,7 @@ use stdweb::web::document; pub fn host() -> Result { document() .location() - .ok_or_else(|| err_msg("can't get location")) + .ok_or_else(|| anyhow!("can't get location")) .and_then(|l| l.host().map_err(Error::from)) }