Why trunk serve doesn't automaticly serve when saving file?

426 Views Asked by At

I'm using trunk serve in my rust project in Windows, everything goes great and compiles and serves, but if I save the file, it doesn't automactly re-compile and serve.

I was expecting it to when I save any of the rust file it to compile and serve, I did trunk serve and tried trunk serve --watch (filepath).

Any fix?

1

There are 1 best solutions below

5
On

some times native method fails, and theres an alternative approach to do it, and if it was written than there where a purpose to do it.

Install Rust and Cargo

install using Cargo(Binstall):
https://crates.io/crates/cargo-watch

cargo install cargo-watch

recompile when changes are detected:

cargo watch -x run

rebuild without running:

cargo watch -x build

ignore changes in a directory:

cargo watch -x run --ignore "directory u want to ignore/*"

to set up a server u can do this:

cargo new rust_server
cd rust_server

add warp to your Cargo.toml:

[dependencies]
warp = "0.3"

than in src/main.rs, set up a simple HTTP server:

use warp::Filter;

#[tokio::main]
async fn main() {
    let hello = warp::path!("hello" / "world")
        .map(|| warp::reply::html("Hello, World!"));

    warp::serve(hello)
        .run(([127, 0, 0, 1], 9000))
        .await;
}

and than use this:

cargo watch -x run