Function kobold::keywords::ref

source ·
pub const fn ref(value: &str) -> &Ref<str>
Expand description

{ ref ... }: diff this value by its reference address.

For strings this is both faster and more memory efficient (no allocations necessary), however it might fail to update if underlying memory has been mutated in place without re-allocations.

use kobold::prelude::*;

struct User {
    name: String,
    email: String,
}

#[component]
fn UserRow(user: &User) -> impl View + '_ {
    view! {
        <tr>
            // If `name` and `email` are always sent to the UI as
            // newly allocated `String`s, it's both safe and faster
            // to diff them by reference than value.
            <td>{ ref user.name }</td>
            <td>{ ref user.email }</td>
        </tr>
    }
}