Here, we'll see the implementation of the adder project, which we already saw how to build and use. Only that which differentiates it from the incr project will be examined.
First of all, there is a problem with the html macro expansion recursion level. It is so deep that it must be increased using the following directives at the beginning of the program:
#![recursion_limit = "128"]
#[macro_use]
extern crate yew;
Without them, a compilation error is generated. With more complex views, an even larger limit is required. The model contains the following fields:
addend1: String,
addend2: String,
sum: Option<f64>,
They represent the following, respectively:
- The text inserted in the first box (addend1).
- The text inserted in the second box (addend2).
- The number calculated and to be displayed in the third box, if the calculation was performed and was successful, or nothing otherwise.
The handled events (that is, the messages) are as follows:
ChangedAddend1(String...