summaryrefslogtreecommitdiffstats
path: root/examples/pokedex.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2019-12-16 21:38:56 +0100
committerLibravatar GitHub <noreply@github.com>2019-12-16 21:38:56 +0100
commit0f2e20f5e5b1f0658ab4e6cbe6fdda9ca97f2b36 (patch)
tree6b4c601bfa0ced1e003f597d7f485be7c108e12c /examples/pokedex.rs
parent3702b109977a249247a0f1be40e57bec2cbaa4e3 (diff)
parent430ab6e44432d044f8444575053d97651f0f7d20 (diff)
downloadiced-0f2e20f5e5b1f0658ab4e6cbe6fdda9ca97f2b36.tar.gz
iced-0f2e20f5e5b1f0658ab4e6cbe6fdda9ca97f2b36.tar.bz2
iced-0f2e20f5e5b1f0658ab4e6cbe6fdda9ca97f2b36.zip
Merge pull request #122 from hecrj/feature/event-subscriptions
Event subscriptions
Diffstat (limited to 'examples/pokedex.rs')
-rw-r--r--examples/pokedex.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/examples/pokedex.rs b/examples/pokedex.rs
index b9daeabd..2d595ec4 100644
--- a/examples/pokedex.rs
+++ b/examples/pokedex.rs
@@ -150,7 +150,6 @@ impl Pokemon {
async fn search() -> Result<Pokemon, Error> {
use rand::Rng;
use serde::Deserialize;
- use std::io::Read;
#[derive(Debug, Deserialize)]
struct Entry {
@@ -179,7 +178,11 @@ impl Pokemon {
let url = format!("https://pokeapi.co/api/v2/pokemon-species/{}", id);
let sprite = format!("https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/{}.png", id);
- let entry: Entry = reqwest::get(&url)?.json()?;
+ let (entry, sprite): (Entry, _) = futures::future::try_join(
+ surf::get(&url).recv_json(),
+ surf::get(&sprite).recv_bytes(),
+ )
+ .await?;
let description = entry
.flavor_text_entries
@@ -188,13 +191,6 @@ impl Pokemon {
.next()
.ok_or(Error::LanguageError)?;
- let mut sprite = reqwest::get(&sprite)?;
- let mut bytes = Vec::new();
-
- sprite
- .read_to_end(&mut bytes)
- .map_err(|_| Error::ImageError)?;
-
Ok(Pokemon {
number: id,
name: entry.name.to_uppercase(),
@@ -203,7 +199,7 @@ impl Pokemon {
.chars()
.map(|c| if c.is_control() { ' ' } else { c })
.collect(),
- image: image::Handle::from_memory(bytes),
+ image: image::Handle::from_memory(sprite),
})
}
}
@@ -211,13 +207,12 @@ impl Pokemon {
#[derive(Debug, Clone)]
enum Error {
APIError,
- ImageError,
LanguageError,
}
-impl From<reqwest::Error> for Error {
- fn from(error: reqwest::Error) -> Error {
- dbg!(&error);
+impl From<surf::Exception> for Error {
+ fn from(exception: surf::Exception) -> Error {
+ dbg!(&exception);
Error::APIError
}