@hiro_moss

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Rustでのlocalhostアクセスエラー

解決したいこと

RustでWEBフレームワークを作成する勉強をしています。
iMac(M1)を使用しています。
ブラウザでlocalhostにアクセスするプログラムを作成し実行しようとしたところエラーが発生しました。
解決方法を教えていただけたら嬉しいです。
宜しくお願いします。

発生している問題・エラー

%cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.19s
     Running `target/debug/todo`
thread 'main' panicked at 'System is not running', /Users/hiro_moss/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-rt-1.1.1/src/system.rs:78:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

該当するソースコード

use actix_web::{get, App, HttpResponse, HttpServer};

#[get("/")]
async fn index() -> Result<HttpResponse, actix_web::Error> {
    let response_body = "Hello world!";
    Ok(HttpResponse::Ok().body(response_body))
}

#[actix_rt::main]
async fn main() -> Result<(), actix_web::Error> {
    HttpServer::new(move || App::new().service(index))
        .bind("0.0.0.0:8080")?
        .run()
        .await?;
    Ok(())
}

自分で試したこと

試しにファイアウォールをオフにしてみましたが、結果は変わりませんでした。

0 likes

1Answer

エラーメッセージの thread 'main' panicked at 'System is not running' で検索すると出てくる通り、 actix のバージョンが古いです。クレートをアップデートしてください。

1Like

Comments

  1. @hiro_moss

    Questioner

    早速のご回答をいただき有難うございます。
    まずは%cargo updateでクレートをアップデートしたのですが同様のエラーが出てしまったため、
    ご指摘いただいたエラーメッセージの部分で検索してみたところ、
    Cargo.tomlにある[dependencies]のactix-rt = "2.2.0"をエラー中で出てくるactix-rt = "1.1.1"に変更するという方法がありましたので試してみたところ上手くいきました。
    助かりました。有難うございます。

Your answer might help someone💌