CSS not loading with Actix web

This is my relevant Rust code:

async fn index() -> Result<HttpResponse> {
    Ok(HttpResponse::build(StatusCode::OK)
        .content_type("text/html;charset=utf-8")
        .body(include_str!("../html/index.html"))
    )
}

index.html:

<link rel="stylesheet" type="text/css" href="css/general.css">

File structure:

├── Cargo.lock
├── Cargo.toml
├── html
│   ├── css
│   │   └── general.css
│   ├── index.html
│   ├── login.html
│   └── register.html
└── src
    └── main.rs

When I run the code and go to 127.0.0.1:8080 the HTML gets loaded as expected but the CSS doesn't. I tried every path to the css file possible (relative from cargo run location etc) but none worked.

How to get the CSS to work?

You, as a web server, should also serve the css files as well. Browsers can only access what the web servers provides, they can't automatically search web server machine's file system.

I think it's better than to keep the front-end and back-end (Rust-code) totally separated than. And maybe let the two sides communicate using Ajax. Writing back-end in Rust seems totally different than in PHP I think.

Check https://actix.rs/docs/static-files/

But to be honest I'm not sure what's the best practice with Actix, in general static files are served through your web server and you connect your web server (for example Nginx) with your web app.

Serving statics from actix works just fine, there is no need for nginx (at least not just for that).

Right, I don't really know Actix, but in general you don't expose app servers to the world in production.