Use reqwest
and tokio
in pokedex
example
This commit is contained in:
parent
28fd9feb40
commit
8f52604987
@ -6,9 +6,9 @@ edition = "2018"
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { path = "../..", features = ["image"] }
|
iced = { path = "../..", features = ["image", "debug"] }
|
||||||
iced_futures = { path = "../../futures", features = ["async-std"] }
|
iced_futures = { path = "../../futures", features = ["tokio"] }
|
||||||
surf = "1.0"
|
reqwest = { version = "0.10", features = ["json"] }
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
@ -27,7 +27,7 @@ enum Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Application for Pokedex {
|
impl Application for Pokedex {
|
||||||
type Executor = iced_futures::executor::AsyncStd;
|
type Executor = iced_futures::executor::Tokio;
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
|
|
||||||
fn new() -> (Pokedex, Command<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 sprite = format!("https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/{}.png", id);
|
||||||
|
|
||||||
let (entry, sprite): (Entry, _) = futures::future::try_join(
|
let (entry, sprite): (Entry, _) = futures::future::try_join(
|
||||||
surf::get(&url).recv_json(),
|
reqwest::get(&url).await?.json(),
|
||||||
surf::get(&sprite).recv_bytes(),
|
reqwest::get(&sprite).await?.bytes(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ impl Pokemon {
|
|||||||
.chars()
|
.chars()
|
||||||
.map(|c| if c.is_control() { ' ' } else { c })
|
.map(|c| if c.is_control() { ' ' } else { c })
|
||||||
.collect(),
|
.collect(),
|
||||||
image: image::Handle::from_memory(sprite),
|
image: image::Handle::from_memory(sprite.as_ref().to_vec()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,9 +206,9 @@ enum Error {
|
|||||||
LanguageError,
|
LanguageError,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<surf::Exception> for Error {
|
impl From<reqwest::Error> for Error {
|
||||||
fn from(exception: surf::Exception) -> Error {
|
fn from(error: reqwest::Error) -> Error {
|
||||||
dbg!(&exception);
|
dbg!(&error);
|
||||||
|
|
||||||
Error::APIError
|
Error::APIError
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,12 @@ log = "0.4"
|
|||||||
[dependencies.futures]
|
[dependencies.futures]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
|
|
||||||
[dependencies.tokio]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio]
|
||||||
version = "0.2"
|
version = "0.2"
|
||||||
optional = true
|
optional = true
|
||||||
features = ["rt-core"]
|
features = ["rt-core", "rt-threaded"]
|
||||||
|
|
||||||
[dependencies.async-std]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.async-std]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@ mod null;
|
|||||||
#[cfg(feature = "thread-pool")]
|
#[cfg(feature = "thread-pool")]
|
||||||
mod thread_pool;
|
mod thread_pool;
|
||||||
|
|
||||||
#[cfg(feature = "tokio")]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))]
|
||||||
mod tokio;
|
mod tokio;
|
||||||
|
|
||||||
#[cfg(feature = "async-std")]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
||||||
mod async_std;
|
mod async_std;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
@ -18,10 +18,10 @@ pub use null::Null;
|
|||||||
#[cfg(feature = "thread-pool")]
|
#[cfg(feature = "thread-pool")]
|
||||||
pub use thread_pool::ThreadPool;
|
pub use thread_pool::ThreadPool;
|
||||||
|
|
||||||
#[cfg(feature = "tokio")]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))]
|
||||||
pub use self::tokio::Tokio;
|
pub use self::tokio::Tokio;
|
||||||
|
|
||||||
#[cfg(feature = "async-std")]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
||||||
pub use self::async_std::AsyncStd;
|
pub use self::async_std::AsyncStd;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user