Skip to main content

View

Derive Macro View 

Source
#[derive(View)]
{
    // Attributes available to this derive:
    #[source]
    #[borrow]
}
Expand description

Derive a View projection for use with pipeline .view() scopes.

Generates a marker ZST (As{ViewName}) and unsafe impl View<Source> for each #[source(Type)] attribute. Use with .view::<AsViewName>() in pipeline and DAG builders.

§Attributes

On the struct:

  • #[source(TypePath)] — one per source event type

On fields:

  • #[borrow] — borrow from source (&source.field) instead of copy
  • #[source(TypePath, from = "name")] — remap field name for a specific source

§Examples

use nexus_rt::View;

#[derive(View)]
#[source(NewOrderCommand)]
#[source(AmendOrderCommand)]
struct OrderView<'a> {
    #[borrow]
    symbol: &'a str,
    qty: u64,
    price: f64,
}

// Generates: struct AsOrderView;
// Generates: unsafe impl View<NewOrderCommand> for AsOrderView { ... }
// Generates: unsafe impl View<AmendOrderCommand> for AsOrderView { ... }