Skip to main content

Column

Trait Column 

Source
pub trait Column<M>: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn label(&self) -> &str;
    fn text(&self, row: &M) -> String;

    // Provided methods
    fn cell<'a>(&self, cx: &'a Cx, row: &M) -> BoxView<'a> { ... }
    fn column_width(&self) -> ColumnWidth { ... }
    fn is_searchable(&self) -> bool { ... }
    fn search_expr(&self, _term: &str) -> Option<Expr<bool>> { ... }
    fn is_sortable(&self) -> bool { ... }
    fn order_by(&self, _descending: bool) -> Option<OrderByExpr> { ... }
    fn includes(&self) -> Includes<M> { ... }
}
Expand description

One table column declares its header, its cell, and its query predicates.

struct Initials;

impl Column<User> for Initials {
    fn name(&self) -> &str {
        "initials"
    }
    fn label(&self) -> &str {
        "Initials"
    }
    fn text(&self, row: &User) -> String {
        row.name
            .split_whitespace()
            .filter_map(|w| w.chars().next())
            .collect()
    }
}

Only name, label and text are required.

Required Methods§

Source

fn name(&self) -> &str

The column’s identifier, distinct within its table.

Source

fn label(&self) -> &str

The header text.

Source

fn text(&self, row: &M) -> String

The row’s value as plain text.

Provided Methods§

Source

fn cell<'a>(&self, cx: &'a Cx, row: &M) -> BoxView<'a>

The row’s table cell.

Source

fn column_width(&self) -> ColumnWidth

The width the column claims.

Source

fn is_searchable(&self) -> bool

Whether the column joins the table’s search.

Source

fn search_expr(&self, _term: &str) -> Option<Expr<bool>>

The predicate a search for term adds.

Source

fn is_sortable(&self) -> bool

Whether the header links to a sort on this column.

Source

fn order_by(&self, _descending: bool) -> Option<OrderByExpr>

The ordering a sort on this column applies.

Source

fn includes(&self) -> Includes<M>

The relations text and cell read.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<M, T> Column<M> for TextColumn<M, T>
where M: Model + Send + Sync + 'static, T: Send + Sync + 'static,

Source§

impl<M> Column<M> for BooleanColumn<M>
where M: Model + Send + Sync + 'static,

Source§

impl<M> Column<M> for ComputedColumn<M>
where M: Model + Send + Sync + 'static,