Use reqwest and tokio in pokedex example

This commit is contained in:
Héctor Ramón Jiménez 2020-02-05 01:40:27 +01:00
parent 28fd9feb40
commit 8f52604987
4 changed files with 17 additions and 17 deletions

View file

@ -6,9 +6,9 @@ edition = "2018"
publish = false
[dependencies]
iced = { path = "../..", features = ["image"] }
iced_futures = { path = "../../futures", features = ["async-std"] }
surf = "1.0"
iced = { path = "../..", features = ["image", "debug"] }
iced_futures = { path = "../../futures", features = ["tokio"] }
reqwest = { version = "0.10", features = ["json"] }
rand = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View file

@ -27,7 +27,7 @@ enum Message {
}
impl Application for Pokedex {
type Executor = iced_futures::executor::AsyncStd;
type Executor = iced_futures::executor::Tokio;
type Message = Message;
fn new() -> (Pokedex, Command<Message>) {
@ -175,8 +175,8 @@ impl Pokemon {
let sprite = format!("https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/{}.png", id);
let (entry, sprite): (Entry, _) = futures::future::try_join(
surf::get(&url).recv_json(),
surf::get(&sprite).recv_bytes(),
reqwest::get(&url).await?.json(),
reqwest::get(&sprite).await?.bytes(),
)
.await?;
@ -195,7 +195,7 @@ impl Pokemon {
.chars()
.map(|c| if c.is_control() { ' ' } else { c })
.collect(),
image: image::Handle::from_memory(sprite),
image: image::Handle::from_memory(sprite.as_ref().to_vec()),
})
}
}
@ -206,9 +206,9 @@ enum Error {
LanguageError,
}
impl From<surf::Exception> for Error {
fn from(exception: surf::Exception) -> Error {
dbg!(&exception);
impl From<reqwest::Error> for Error {
fn from(error: reqwest::Error) -> Error {
dbg!(&error);
Error::APIError
}