Use reqwest
and tokio
in pokedex
example
This commit is contained in:
parent
28fd9feb40
commit
8f52604987
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ log = "0.4"
|
||||
[dependencies.futures]
|
||||
version = "0.3"
|
||||
|
||||
[dependencies.tokio]
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio]
|
||||
version = "0.2"
|
||||
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"
|
||||
optional = true
|
||||
|
||||
|
@ -4,10 +4,10 @@ mod null;
|
||||
#[cfg(feature = "thread-pool")]
|
||||
mod thread_pool;
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))]
|
||||
mod tokio;
|
||||
|
||||
#[cfg(feature = "async-std")]
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
||||
mod async_std;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
@ -18,10 +18,10 @@ pub use null::Null;
|
||||
#[cfg(feature = "thread-pool")]
|
||||
pub use thread_pool::ThreadPool;
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "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;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user