Expand description
The primitives ferrovue’s runtime crates share: Vue’s HTML escaping, and numbers written as JavaScript writes them.
§Example
let mut out = String::from("<p>");
ferrovue::escape_into(&mut out, "Tom & Jerry");
out.push(' ');
ferrovue::push_number(&mut out, 0.1 + 0.2);
out.push_str("</p>");
assert_eq!(out, "<p>Tom & Jerry 0.30000000000000004</p>");Structs§
- Js
- A number written as JavaScript writes it, for
format!in generated code:${n}in a template literal,"#" + n,n.toString().
Functions§
- escape_
into escapeHtml:",&,',<and>, and nothing else.- js_max
Math.maxof two numbers:NaNif either is, where Rust’sf64::maxignores aNaN.- js_min
Math.minof two numbers:NaNif either is, where Rust’sf64::minignores aNaN.- js_
round Math.round: the nearest integer, a half rounding up toward +∞ (-2.5to-2, where Rust’sf64::roundgives-3), and-0from-0.5up to zero, which1 / Math.round(x)shows.- js_
to_ fixed Number.prototype.toFixed(digits): the number rounded todigitsplaces, from its exact binary value. An exact tie rounds away from zero, where Rust’s formatting rounds it to even; at 10²¹ and beyond, JavaScript writes the number asString(x)does.- push_
int String(n)for an integer, which is whattoDisplayStringandescapeHtmlmake of a number.- push_
number Number.prototype.toString(): JavaScript’s shortest round-trip digits, laid out as ECMAScript lays them out:0.30000000000000004,1e+21,1.5e-7,NaN,-Infinity.