Skip to main content

View

Trait View 

Source
pub trait View<B>: Any {
    // Required methods
    fn apply(&mut self, event: &Event<B>);
    fn cursor(&self) -> u64;
    fn as_any(&self) -> &dyn Any;
}
Expand description

A live view the DB drives type-erased, as dyn View<B>.

Deliberately object-safe — no associated types, no Self-returning methods — which is exactly why it is not : Projection. Projection has type State and state(&self) -> &Self::State, and an associated type makes dyn Projection impossible. A View carries only what the registry needs to drive it (apply/cursor) and downcast it (as_any); the query methods live on the concrete type, reached after downcast via crate::Salamander::view.

IndexedView implements both View (so the registry can store it as dyn View) and Projection (so replay_into/view_at still build it on demand for time-travel). A concrete type implementing two traits is fine; only the stored form is erased.

Required Methods§

Source

fn apply(&mut self, event: &Event<B>)

Fold one event into the view. Same determinism contract as Projection::apply (query-layer design §6, INV-2).

Source

fn cursor(&self) -> u64

All events with offset < cursor have been applied.

Source

fn as_any(&self) -> &dyn Any

Upcast to dyn Any so the registry can downcast to the concrete view type on query. (Box<dyn View<B>> is not automatically dyn Any; this is the standard bridge.)

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<K, V, B> View<B> for IndexedView<K, V, B>
where K: Ord + Hash + Clone + 'static, V: 'static, B: 'static,