Html

Enum Html 

Source
pub enum Html {
    Text {
        text: String,
        hash: u64,
    },
    Element {
        tag: String,
        attrs: Vec<(String, String)>,
        key: Option<String>,
        children: Vec<Html>,
        tag_key_h: u64,
        attrs_h: u64,
        children_h: u64,
    },
}

Variants§

§

Text

Fields

§text: String
§hash: u64
§

Element

Fields

§attrs: Vec<(String, String)>
§children: Vec<Html>
§tag_key_h: u64

Three accumulators rather than one hash, so that the hash is a function of the node’s structure and not of the order the builder methods happened to be called in. Getting this wrong makes two identical subtrees hash differently, and a differ that trusts a hash it cannot reproduce is worse than one with no hash at all.

§attrs_h: u64
§children_h: u64

Implementations§

Source§

impl Html

Source

pub fn text(s: impl Into<String>) -> Html

Source

pub fn el(tag: impl Into<String>) -> Html

Start an element. Attributes and children are added with the builder methods below; each step costs one multiply per byte added, and nothing is ever rehashed.

Source

pub fn attr(self, name: impl Into<String>, value: impl Into<String>) -> Html

Source

pub fn attr_if( self, cond: bool, name: impl Into<String>, value: impl Into<String>, ) -> Html

Conditional attribute — the (if t.done "done" "") shape from the sketch, without emitting an empty attribute the differ would then have to churn on.

Source

pub fn on(self, event: &str, command: Value) -> Html

A handler in view compiles to a declarative attribute — no user JavaScript exists in Mode A (§5.1 “Input capture”), so script-src can stay near-empty. command is the serialised command constructor the thin client posts back up the socket.

Source

pub fn key(self, k: impl Into<String>) -> Html

Source

pub fn child(self, c: Html) -> Html

Source

pub fn children(self, cs: impl IntoIterator<Item = Html>) -> Html

Source

pub fn rehash(&self) -> Html

Rebuild the tree, recomputing every structural hash bottom-up.

Needed after in-place surgery on a node: an edit deep in a tree invalidates the hash of every ancestor, and a stale hash is worse than no hash — the differ would skip a subtree that did change.

Source

pub fn hash(&self) -> u64

Source

pub fn key_of(&self) -> Option<&str>

Source

pub fn child_at(&self, i: usize) -> Option<&Html>

Source

pub fn node_count(&self) -> usize

Node count — the denominator of “how much of the tree did the diff actually touch”.

Source

pub fn to_wire(&self) -> Value

The wire encoding: a text node is a JSON string, an element is [tag, attrs, children].

Positional and terse because it rides in every patch. §4.4 specifies a field-tagged binary encoding for Beck↔Beck traffic; the thin client is a browser, and JSON costs it zero bytes of decoder — see crate::patch::Codec for the measured comparison.

Source

pub fn render(&self) -> String

Server-side render. “First paint is free SSR: evaluate pure view against the current accumulator, ship HTML.”

Emitted without any inter-element whitespace, deliberately: patch paths are child indices, and a pretty-printer would insert text nodes that the server’s tree does not have, so the first patch after hydration would address the wrong node.

Source

pub fn render_into(&self, out: &mut String)

Trait Implementations§

Source§

impl Clone for Html

Source§

fn clone(&self) -> Html

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Html

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Html

Source§

fn cmp(&self, other: &Html) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Html

Source§

fn eq(&self, other: &Html) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Html

Source§

fn partial_cmp(&self, other: &Html) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Html

Source§

impl StructuralPartialEq for Html

Auto Trait Implementations§

§

impl Freeze for Html

§

impl RefUnwindSafe for Html

§

impl Send for Html

§

impl Sync for Html

§

impl Unpin for Html

§

impl UnwindSafe for Html

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.