Skip to main content

node_ref

Macro node_ref 

Source
macro_rules! node_ref {
    ($(#[$attr:meta])* $vis:vis const $name:ident: NodeRef<$signals:ty>) => { ... };
}
Expand description

Declares a NodeRef constant named after its own path.

The input is the constant’s declaration without a value. The macro writes that constant, with the name module_path!() and the identifier give it, and a const _ that reads it back through self::. The second item stops the build where the declaration sits in a function body, because two functions in one module could otherwise each declare a constant of one identifier and give two constants one name. Attributes go on both items.

use hypersig::html::input;
use hypersig::{NodeRef, Signals};
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize)]
struct Search {
    query: String,
}

hypersig::node_ref!(pub const FIELD: NodeRef<Search>);

let field = input().node_ref(FIELD).bind(Search::query());
assert!(field.render().contains(&format!(r#"data-hs-ref="{}::FIELD""#, module_path!())));

§Compile errors

A declaration inside a function body, where self::NAME does not reach the constant, and a type other than NodeRef<..>.