Skip to main content

ViewLogic

Trait ViewLogic 

Source
pub trait ViewLogic:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &'static str;
    fn title(&self) -> &'static str;
    fn render(
        &self,
        args: &ViewArgs,
        ctx: &Context,
    ) -> Result<ViewData, ApiError>;

    // Provided method
    fn params(
        &self,
        _ctx: &Context,
        _asked: &ViewArgs,
    ) -> Result<Vec<Param>, ApiError> { ... }
}
Expand description

One repository’s view.

params and render both run on every request, against one Context, so a view reading three tables reads each of them once however many of its parts consult them.

Required Methods§

Source

fn name(&self) -> &'static str

The route segment and ?view= value. It must be made of unreserved URL characters, and may not take a reserved name or one a table has; building a crate::Server over such a view panics.

Source

fn title(&self) -> &'static str

The heading the page and the shell’s switcher show.

Source

fn render(&self, args: &ViewArgs, ctx: &Context) -> Result<ViewData, ApiError>

Provided Methods§

Source

fn params( &self, _ctx: &Context, _asked: &ViewArgs, ) -> Result<Vec<Param>, ApiError>

The controls at the top of the page, rebuilt per request like a schema, so a select can be filled from a table.

asked is what the address carried, before defaults are filled in, so one parameter’s options may depend on another’s value. A parameter whose options are built that way should give a default drawn from the same values: an answer the new options do not offer is replaced by that default rather than kept.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§