The development server
cargo hypersig dev builds and restarts the server after each change, and the open tab reloads with the signals the visitor changed. cargo hypersig new writes a project to start from.
Install it
cargo hypersig comes from the crate hypersig_cli. Its dev command builds with blaze, an incremental build tool for Rust, so install both:
cargo install --locked hypersig_cli
curl -fsSL https://raw.githubusercontent.com/indexable-inc/blaze/main/install.sh | shWhere no blaze command runs, cargo hypersig dev stops before it builds anything and prints the second line above.
Run the server
In the project's directory, run cargo hypersig dev where you would run cargo run. It builds the server, starts it, and builds and starts it again each time a file it is built from changes. Besides Cargo's own lines, it prints which files it watches and the binary it started:
cargo hypersig devWatching the `.rs` files, `Cargo.toml`, and `Cargo.lock` under /home/me/counter
Started `target/debug/counter`
Restarted `target/debug/counter`The line names the binary and no address, because the server prints its own address where it prints one. The Quick start's server prints none and listens on http://127.0.0.1:3000. The server writes to the same terminal, and one Ctrl+C stops both. The state the server holds in memory starts over at each restart.
What starts a build
A change to one of these files starts a build:
- Each
.rsfile,Cargo.toml, andCargo.lockunder the directory it runs in, except insidetarget,node_modules, and directories whose name starts with.. - Each file the last build read, such as a stylesheet that
include_str!puts into the binary, except the downloaded crates under Cargo's home directory. TheWatchingline counts them as "more files the build read". - A file saved while a build runs starts the next one.
- A change that builds the same binary, such as an edit to a file the server is not built from, leaves the running server as it is.
How a change is built
Each build runs cargo check and blaze build at the same time. blaze compiles only the functions that changed, so the wait after an edit is mostly the check's. The check decides whether the code compiles: when it prints an error, the server of the last build keeps running until a change that compiles. When the check passes and blaze fails, the line blaze did not build it, so Cargo builds it appears and cargo build writes the binary.
blaze's first build on a machine compiles every dependency and takes longer than Cargo's. So Cargo builds the first server, and builds each change until blaze's first build ends.
When the server exits on its own, for example after a panic in main, The server stopped with ...; it starts again after the next change. appears, and the next change starts it again even when the binary is the same.
Build options and server arguments
The arguments before -- go to cargo check and blaze build, and the arguments after it go to the server:
cargo hypersig dev [<build options>] [-- <args>]
cargo hypersig dev -p web -- --verbose| Situation | What cargo hypersig dev does |
|---|---|
| The build has more than one binary | Stops with the build has ...; name one with --bin or -p, which lists them |
| The build has no binary, as a Cloudflare project | Stops and says that a Cloudflare project runs under npx wrangler dev |
The options include --release, -r, or --profile | Prints a warning that pages will not reload, because only a debug build reloads them |
| The options change the target directory | Reads it once at the start, so a later change to it needs cargo hypersig dev started again |
The open tab reloads
When the server serves its pages from a debug build, with hypersig_runtime() on its router, each open tab reloads by itself once a new server has started in place of the one that rendered it. Any restart of a debug build does this, including cargo run run again by hand, and so does a page under a Base.
The signals the reload keeps
The reloaded tab keeps the signals the visitor changed, such as a half-typed draft. Take this page, whose input is bound to draft and whose list notes only the server changes:
use hypersig::html::{button, div, each, input, li, ul};
use hypersig::{Action, Page, Patches, Route};
#[derive(Signals, Serialize, Deserialize)]
struct Notes {
draft: String,
notes: Vec<String>,
}
hypersig::routes! {
fn pages(Router<()>);
const INDEX: Route = "/" => index;
action ADD: Action<Notes, String> = post "/notes" => add;
}
async fn index((): (), (): ()) -> Page<Notes> {
let draft = Notes::draft();
let empty = Notes { draft: String::new(), notes: Vec::new() };
Page::new("Notes", empty).child(
div()
.child(input().bind(draft))
.child(button().on_click(ADD.call_with(draft)).text("Add"))
.child(ul().child(each(Notes::notes(), |note| li().bind_text(note)))),
)
}
async fn add((): (), text: String) -> Patches<Notes> {
Patches::new()
.list(Notes::notes().patch_append(&[text]))
.signals(Notes::draft().patch(String::new()))
}The tab keeps each top-level signal whose value differs from the value the server last wrote into it, in the page or in a patch, and every other signal takes the new server's value. Say the visitor adds one note and then types Buy mi. notes still holds what the server's patch wrote, and draft does not. After the reload, the input shows Buy mi again and the list is empty, because this server keeps no notes and its page starts with none. A later visit to the page starts from the server's values.
The values go back only where the new page shows the same path and query, and its signal struct has the same field names and field types. Otherwise the page starts from the server's values.
These cases are not checked. In each, the reload restores less than the visitor typed, or a value shaped like the old struct:
- For a field whose type is another
Signalsstruct, only that type's name is compared. A change inside the nested struct alone is not detected, and the value restored into that field keeps its old fields until the next reload. - A page whose signal struct implements
Signalsby hand, without#[derive(Signals)], restores nothing. - Where the browser blocks
sessionStorageor it is full, nothing is kept, and the reloaded page starts from the server's values.
Start a project with cargo hypersig new
cargo hypersig new writes a project from a template, in place of cargo new and the two files the Quick start writes by hand:
cargo hypersig new counter
cd counter
cargo hypersig devWithout --host, the template is server: a counter like the quick start's, whose buttons come from hypersig_ui and whose main calls hypersig::serve on port 3000, with two tests of its handlers, Clippy's pedantic lints on in Cargo.toml, and a Dockerfile. --host cloudflare and --host vercel write a project for those hosts, which Choosing a host compares.
--host | Files it writes | Run it on this machine |
|---|---|---|
server | Cargo.toml, src/main.rs, Dockerfile, .dockerignore, .gitignore, AGENTS.md, CLAUDE.md | cargo hypersig dev |
cloudflare | Cargo.toml, src/lib.rs, wrangler.toml, rust-toolchain.toml, .gitignore, AGENTS.md, CLAUDE.md | npx wrangler dev |
vercel | Cargo.toml, api/app.rs, vercel.json, rust-toolchain.toml, .vercelignore, .gitignore, AGENTS.md, CLAUDE.md | cargo run |
After writing the files, it prints the commands that run the project on this machine and deploy it.
- The last part of the path names the package. It takes lowercase ASCII letters, digits,
-, and_, starting with a letter or_, and not a Rust keyword or a name Cargo refuses, such astestorbuild. A Cloudflare Worker's name holds no_. A refused name stops the command before it writes a file. - A path that already exists stops the command, which then names
cargo hypersig add <host>.addmoves the project in the current directory to a host, and Choosing a host covers it. - The new directory becomes a Git repository, as with
cargo new, unless it is inside one already.
Next
- Elements and attributes starts the guide, with how the HTML is built.
- Signals kept across page loads keeps chosen signals in the browser's storage on every page load, in any build.
- Choosing a host builds the project for a host.