Yew: impl From error using FetchService

Created on 5 Feb 2020  路  4Comments  路  Source: yewstack/yew

Question

How can the error be resolved?

What I've tried (optional)

FetchService get data structure in JSON format

#[derive(Debug, Deserialize)]
pub struct Data {
    value: String,
}

pub enum Message {
    FetchReady(Result<Data, anyhow::Error>),
}

let request = Request::get(String::from("/data.json"))
    .body(Nothing)
    .unwrap();

let fetch_callback =
    self.link
        .callback(|response: Response<Json<Result<Data, anyhow::Error>>>| {
            let (meta, Json(data)) = response.into_parts();
            if meta.status.is_success() {
                Message::FetchReady(data)
            } else {
                Message::FetchReady(Err(anyhow!(
                    "{}: error getting file",
                    meta.status
                )))
            }
        });

let task = self.fetch_service.fetch(request, fetch_callback);
                                             ~~~~~~~~~~~~~

the trait bound yew::format::json::Json<std::result::Result<my::form::Data, anyhow::Error>>: std::convert::From<std::result::Result<std::string::String, failure::error::Error>> is not satisfied

the trait std::convert::From<std::result::Result<std::string::String, failure::error::Error>> is not implemented for yew::format::json::Json<std::result::Result<my::form::Data, anyhow::Error>>

help: the following implementations were found:
> as std::convert::From>>
> as std::convert::From, failure::error::Error>>>

question

All 4 comments

It seems like failures Error type is part of yews public API. You can't just replace failure with anyhow in the fetch service examples.

To be a little more precise, the Text type seems to be what's causing the issue here.

@kellytk which version (or branch) of yew are you using? We recently changed from failure to anyhow on master so this might be tripping you up

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zethra picture zethra  路  5Comments

agausmann picture agausmann  路  3Comments

thienpow picture thienpow  路  5Comments

thienpow picture thienpow  路  3Comments

ghost picture ghost  路  5Comments