Panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime' #1567
Answered
by
hecrj
Amazingkenneth
asked this question in
Q&A
-
I am trying to grab data from the web for initialization. PS C:\Users\amazi\test> cargo run
Compiling test v0.1.0 (C:\Users\amazi\test)
Finished dev [unoptimized + debuginfo] target(s) in 7.95s
Running `target\debug\test.exe`
thread '<unnamed>' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', D:\Scoop\persist\rustup-msvc\.cargo\registry\src\github.com-1ecc6299db9ec823\hyper-0.14.23\src\client\connect\dns.rs:121:24
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Here are the source code for representing: src/main.rs: #![allow(dead_code)]
use iced::executor;
use iced::{Application, Command, Element, Settings, Theme};
use reqwest;
pub fn main() -> iced::Result {
Hello::run(Settings::default())
}
#[derive(Debug)]
enum Error {
SomeError,
}
enum Hello {
Loading,
Loaded(Result<State, Error>),
}
#[derive(Debug)]
struct State;
impl State {
async fn grab() -> Result<State, Error> {
let cli = reqwest::Client::new();
let content: String = cli
.get("http://www.httpbin.org/get")
.send()
.await
.expect("Cannot send request")
.text()
.await
.expect("Cannot convert response to text.");
println!("{}", content);
Ok(State)
}
}
#[derive(Debug)]
enum Message {
Loading,
Loaded(Result<State, Error>),
}
impl Application for Hello {
type Executor = executor::Default;
type Flags = ();
type Message = Message;
type Theme = Theme;
fn new(_flags: ()) -> (Hello, Command<Self::Message>) {
(
Hello::Loading,
Command::perform(State::grab(), Message::Loaded),
)
}
fn title(&self) -> String {
String::from("A cool application")
}
fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
Command::none()
}
fn view(&self) -> Element<Self::Message> {
"Hello, world!".into()
}
} Cargo.toml: [package]
name = "test"
version = "0.1.0"
edition = "2021"
[dependencies]
iced = "0.5"
reqwest = "0.11"
tokio = { version = "1", features = ["full"] } How can I solve the problem? |
Beta Was this translation helpful? Give feedback.
Answered by
hecrj
Dec 1, 2022
Replies: 1 comment 1 reply
-
Enable the iced = { version = "0.5", features = ["tokio"] } |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Amazingkenneth
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Enable the
tokio
feature iniced
: