日本語

Reading a compile error

How to read the compile errors that hypersig's traits and constants produce: which line names the mistake, which lines to skip, and where to look up a message this page does not list.

Reading a compile error

Most mistakes in a hypersig page fail to compile, and hypersig writes the first line of the error for its own traits, so that line names the mistake in the page's terms. The note: lines below it say what the trait accepts. The help: lines and the required by a bound notes point into hypersig's source, and you can skip them until the first line is not enough. Here is the whole error for an action whose handler returns a String:

error[E0277]: `String` is not a reply of an action on the page whose signals are `Board`
  --> src/main.rs:11:1
   |
11 | / hypersig::routes! {
12 | |     fn actions(Router<()>);
13 | |     action RENAME: Action<Board, String> = post "/rename" => rename;
14 | | }
   | |_^ the trait `IntoActionResponse<Board>` is not implemented for `String`
   |
   = note: an action's handler returns `Patches<Board>`, a `SignalPatch<Board>`, a `ListPatch<Board>`, a tuple of response parts and one of those, or a `Result` of one of those whose error implements `IntoResponse`
note: required by a bound in `hypersig::RouterExt::action`
  --> src/axum.rs
   |
   |     fn action<S, A, H, M, Fut, P>(self, action: Action<S, A>, handler: H) -> Self
   |        ------ required by a bound in this associated function
...
LineWhat to do with it
error[E0277]: ...Read it first. It names the value and the page in hypersig's words.
--> and the marked linesThe place in your code. For a handler this is the routes! block or the handler's name on its line.
= note:What hypersig accepts in that place
help:, required by a bound, note: insideLines of hypersig's source. Skip them until the lines above are not enough.

E0277 on a line of routes!

routes! hands each handler to the router, so an error about a handler points at the routes! block or at the handler's name on its line. cannot serve this page or action with not a handler of the router's state and the arguments means the parameters are off: a handler takes the router's state first and the arguments second, as async fn add(state: AppState, draft: String), with at most one extractor between them. The first slot is () on a router without state, and the second is () for a page without path parameters or an action without arguments. is not a reply of an action means the return type is off, and its note: lists the types an action's handler returns.

hypersig::routes! {
    fn actions(Router<()>);
    // error[E0277]: `String` is not a reply of an action on the page whose
    // signals are `Board`
    action RENAME: Action<Board, String> = post "/rename" => rename;
}

async fn rename((): (), title: String) -> String {
    title
}

E0080 on a constant

A route's path, an Id, an attr! or tag! name, an Origin, and a SafeUrl::new are checked while the compiler evaluates the constant that holds them. A broken rule reads evaluation panicked: followed by the rule, and the line below names the constant, as in evaluation of MEMBER failed. The note: inside lines that follow show the assert! in hypersig that holds the rule. The check runs only for a value declared as a const, so a constructor called in a function body panics at run time with the same message.

use hypersig::html::Id;

// error[E0080]: evaluation panicked: an id holds no whitespace
const EMAIL: Id = Id::new("e mail");

Writing a computed signal

A field marked #[signals(computed)] is a Sig<S, T, Computed>, which has no set, toggle, list statement, bind, or patch. bind reports E0277, a signal marked Computed cannot be written, and a method such as set reports E0599, the method set exists for struct Sig<Cart, f64, Computed>, but its trait bounds were not satisfied, with Computed: Writable among the bounds. Both mean the same thing: write a signal the expression reads, and the computed one follows. The reverse mistake, passing an unmarked field to Page::computed, reports E0277, Page::computed takes a field marked #[signals(computed)].

use hypersig::Signals;
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize)]
struct Cart {
    price: f64,
    quantity: i32,
    #[signals(computed)]
    total: f64,
}

// error[E0277]: a signal marked `Computed` cannot be written
let field = input::<Cart>().bind(Cart::total());

Other messages

  • E0599 no associated function or constant named on a struct with #[derive(Signals)]: the field name is misspelled, and the help: line names the field it is closest to.
  • E0277, Sig<Other, bool> is not an expression of type bool on the page whose signals are Counter: the value has another type, or reads the signals of another page. The help: line says which page it belongs to.
  • An error that names none of the above: each case under crates/hypersig/tests/ui/fail is one mistake that must not compile, with the compiler's message beside it in a .stderr file, so searching that directory for the first line of your error finds the mistake it stands for.

The other Learn pages show the compile error for the mistake their own types prevent, such as a misspelled signal on The signal struct.

Next