summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-14 00:32:05 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-14 00:32:05 +0100
commitf0381a7fb305a371208df62d339540ce3d48f9da (patch)
tree59a855a7ba5c3d65a98929d4d3a7e00211218839 /examples
parentffa46898d983fc15ce6051a427622c058ce4e151 (diff)
downloadiced-f0381a7fb305a371208df62d339540ce3d48f9da.tar.gz
iced-f0381a7fb305a371208df62d339540ce3d48f9da.tar.bz2
iced-f0381a7fb305a371208df62d339540ce3d48f9da.zip
Use `surf` in `pokedex` example
Diffstat (limited to 'examples')
-rw-r--r--examples/pokedex.rs23
-rw-r--r--examples/timer.rs2
2 files changed, 10 insertions, 15 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
}
diff --git a/examples/timer.rs b/examples/timer.rs
index b64b3ef5..367c5b2b 100644
--- a/examples/timer.rs
+++ b/examples/timer.rs
@@ -92,7 +92,7 @@ impl Application for Timer {
let duration = Text::new(format!(
"{:0>2}:{:0>2}:{:0>2}.{:0>2}",
seconds / HOUR,
- seconds / MINUTE,
+ (seconds % HOUR) / MINUTE,
seconds % MINUTE,
self.duration.subsec_millis() / 10,
))