Skip to content

Commit

Permalink
Merge branch 'master' into web-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Jan 19, 2020
2 parents c1f621a + ffadafe commit c85fd29
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 68 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ 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 }
cfg-if = "0.1"
cfg-match = "0.2"
console_error_panic_hook = { version = "0.1", optional = true }
failure = "0.1"
gloo = { version = "0.2", optional = true }
http = "0.2"
indexmap = "1.0.2"
Expand All @@ -39,6 +39,7 @@ serde_json = "1.0"
serde_yaml = { version = "0.8.3", optional = true }
slab = "0.4"
stdweb = { version = "0.4.20", optional = true }
thiserror = "1"
toml = { version = "0.5", optional = true }
wasm-bindgen = { version = "0.2.58", optional = true }
yew-macro = { version = "0.11.1", path = "crates/macro" }
Expand Down Expand Up @@ -118,7 +119,6 @@ agent = ["bincode"]
yaml = ["serde_yaml"]
msgpack = ["rmp-serde"]
cbor = ["serde_cbor"]
cbor_packed = ["serde_cbor"]

[workspace]
members = [
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,33 @@ if you tell the `cargo-web` to build for them using the `--target` parameter.

* [`yew-wasm-pack-template`](https://github.com/yewstack/yew-wasm-pack-template)
* [`yew-wasm-pack-minimal`](https://github.com/yewstack/yew-wasm-pack-minimal)

## Contributors

### Code Contributors

This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="https://github.com/yewstack/yew/graphs/contributors"><img src="https://opencollective.com/yew/contributors.svg?width=890&button=false" /></a>

### Financial Contributors

Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/yew/contribute)]

#### Individuals

<a href="https://opencollective.com/yew"><img src="https://opencollective.com/yew/individuals.svg?width=890"></a>

#### Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/yew/contribute)]

<a href="https://opencollective.com/yew/organization/0/website"><img src="https://opencollective.com/yew/organization/0/avatar.svg"></a>
<a href="https://opencollective.com/yew/organization/1/website"><img src="https://opencollective.com/yew/organization/1/avatar.svg"></a>
<a href="https://opencollective.com/yew/organization/2/website"><img src="https://opencollective.com/yew/organization/2/avatar.svg"></a>
<a href="https://opencollective.com/yew/organization/3/website"><img src="https://opencollective.com/yew/organization/3/avatar.svg"></a>
<a href="https://opencollective.com/yew/organization/4/website"><img src="https://opencollective.com/yew/organization/4/avatar.svg"></a>
<a href="https://opencollective.com/yew/organization/5/website"><img src="https://opencollective.com/yew/organization/5/avatar.svg"></a>
<a href="https://opencollective.com/yew/organization/6/website"><img src="https://opencollective.com/yew/organization/6/avatar.svg"></a>
<a href="https://opencollective.com/yew/organization/7/website"><img src="https://opencollective.com/yew/organization/7/avatar.svg"></a>
<a href="https://opencollective.com/yew/organization/8/website"><img src="https://opencollective.com/yew/organization/8/avatar.svg"></a>
<a href="https://opencollective.com/yew/organization/9/website"><img src="https://opencollective.com/yew/organization/9/avatar.svg"></a>
5 changes: 4 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub fn main() {
println!("cargo:rustc-cfg=feature=\"wasm_bindgen_test\"");
} else if cfg!(all(feature = "web_sys", not(feature = "doc_test"))) {
let target = env::var("TARGET").unwrap_or_default();
panic!("Selected target `{}` is not compatible with web-sys", target);
panic!(
"Selected target `{}` is not compatible with web-sys",
target
);
}
}
2 changes: 1 addition & 1 deletion examples/dashboard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Denis Kolodin <deniskolodin@gmail.com>"]
edition = "2018"

[dependencies]
failure = "0.1"
anyhow = "1"
serde = "1"
serde_derive = "1"
yew = { path = "../..", features = ["toml"] }
2 changes: 1 addition & 1 deletion examples/dashboard/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion examples/npm_and_rest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Denis Kolodin <deniskolodin@gmail.com>"]
edition = "2018"

[dependencies]
failure = "0.1"
anyhow = "1"
serde = "1"
serde_derive = "1"
stdweb = "0.4.20"
Expand Down
5 changes: 2 additions & 3 deletions examples/npm_and_rest/src/gravatar.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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
)))
Expand Down
2 changes: 1 addition & 1 deletion examples/npm_and_rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
29 changes: 0 additions & 29 deletions src/format/cbor_packed.rs

This file was deleted.

16 changes: 8 additions & 8 deletions src/format/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> From<$crate::format::Text> for $type<Result<T, ::failure::Error>>
impl<T> From<$crate::format::Text> for $type<Result<T, ::anyhow::Error>>
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)),
}
}
Expand All @@ -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<T> From<$crate::format::Binary> for $type<Result<T, ::failure::Error>>
impl<T> From<$crate::format::Binary> for $type<Result<T, ::anyhow::Error>>
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)),
}
}
Expand All @@ -57,11 +57,11 @@ macro_rules! text_format_is_an_error {
($type:ident) => {
use $crate::format::FormatError;

fn to_string<T>(_value: T) -> Result<String, failure::Error> {
fn to_string<T>(_value: T) -> Result<String, ::anyhow::Error> {
Err(FormatError::CantEncodeBinaryAsText.into())
}

fn from_str<T>(_s: &str) -> Result<T, failure::Error> {
fn from_str<T>(_s: &str) -> Result<T, ::anyhow::Error> {
Err(FormatError::ReceivedTextForBinary.into())
}

Expand Down
14 changes: 5 additions & 9 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,8 +14,6 @@ pub mod macros;
pub mod bincode;
#[cfg(feature = "cbor")]
pub mod cbor;
#[cfg(feature = "cbor_packed")]
pub mod cbor_packed;
pub mod json;
#[cfg(feature = "msgpack")]
pub mod msgpack;
Expand All @@ -29,8 +27,6 @@ pub mod yaml;
pub use self::bincode::Bincode;
#[cfg(feature = "cbor")]
pub use self::cbor::Cbor;
#[cfg(feature = "cbor_packed")]
pub use self::cbor_packed::CborPacked;
pub use self::json::Json;
#[cfg(feature = "msgpack")]
pub use self::msgpack::MsgPack;
Expand All @@ -54,14 +50,14 @@ pub type Binary = Result<Vec<u8>, Error>;
pub type Format<T> = Result<T, Error>;

/// 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,
}
6 changes: 3 additions & 3 deletions src/format/nothing.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! 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)]
pub struct Nothing;

impl Into<Text> for Nothing {
fn into(self) -> Text {
Err(err_msg("nothing"))
bail!("nothing")
}
}

Expand All @@ -21,7 +21,7 @@ impl From<Text> for Nothing {

impl Into<Binary> for Nothing {
fn into(self) -> Binary {
Err(err_msg("nothing"))
bail!("nothing")
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/services/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use crate::format::Text;
use cfg_if::cfg_if;
use cfg_match::cfg_match;
use failure::Fail;
use std::fmt;
use thiserror::Error;
cfg_if! {
if #[cfg(feature = "std_web")] {
#[allow(unused_imports)]
Expand All @@ -19,9 +19,9 @@ cfg_if! {
}

/// Represents errors of a storage.
#[derive(Debug, Fail)]
#[derive(Debug, Error)]
enum StorageError {
#[fail(display = "restore error")]
#[error("restore error")]
CantRestore,
}

Expand Down
11 changes: 5 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This module contains useful utils to get information about the current document.

use anyhow::{anyhow, Error};
use cfg_if::cfg_if;
use cfg_match::cfg_match;
use failure::{err_msg, Error};
use std::marker::PhantomData;
cfg_if! {
if #[cfg(feature = "std_web")] {
Expand Down Expand Up @@ -32,17 +32,16 @@ pub fn document() -> Document {
pub fn host() -> Result<String, Error> {
let location = document()
.location()
.ok_or_else(|| err_msg("can't get location"))?;
.ok_or_else(|| anyhow!("can't get location"))?;

#[cfg(feature = "std_web")]
let host = location.host().map_err(Error::from)?;

#[cfg(feature = "web_sys")]
let host = location.host().map_err(|e| {
err_msg(
e.as_string()
.unwrap_or_else(|| String::from("error not recoverable")),
)
anyhow!(e
.as_string()
.unwrap_or_else(|| String::from("error not recoverable")),)
})?;

Ok(host)
Expand Down

0 comments on commit c85fd29

Please sign in to comment.