Skip to main content

Length

Trait Length 

Source
pub trait Length {
    type Count: Display + Truthy;

    // Required method
    fn length(&self) -> Self::Count;
}
Expand description

How many items {{ rows.length }} reports.

This follows handlebars.js, where length is an ordinary property lookup and a JS array carries one. Only lists have it here: a String deliberately does not, because JS counts UTF-16 code units and Rust would count either bytes or chars — all three disagree on the same text, and a quietly different number is exactly what this crate promises never to produce.

Count is an associated type rather than a plain usize so that a list which was never set can report nothing at all, as an undefined value does in handlebars.js, while a list with no items in it reports 0.

Required Associated Types§

Source

type Count: Display + Truthy

What the count renders as: a number, or nothing at all when the list was never set.

Required Methods§

Source

fn length(&self) -> Self::Count

How many items this holds.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, const N: usize> Length for [T; N]

Source§

impl<T: Length + ?Sized> Length for &T

Source§

type Count = <T as Length>::Count

Source§

fn length(&self) -> T::Count

Source§

impl<T> Length for Vec<T>

Source§

impl<T> Length for [T]

Implementors§

Source§

impl Length for Empty

A variable that was never set is absent, and absent has no count — {{ rows.length }} writes nothing, rather than 0, exactly as it does for an undefined value in handlebars.js.

Source§

impl<T> Length for Absent<T>