Skip to main content

Projection

Struct Projection 

Source
pub struct Projection { /* private fields */ }
Expand description

Pull-based, queryable view of the event stream

Projection consumes events from an EventReceiver in the background and provides read access to accumulated state at any time. TUI applications query the projection on each render frame without interacting with the event system directly.

Construction starts a background drain task via tokio::spawn. The task reads events from the receiver, translates each into an Entry, and appends it to internal storage. When the event channel closes (all senders dropped), the task marks the projection as complete.

Query methods take &self and return cloned snapshots of the accumulated state. The drain task and query callers synchronize through a RwLock, allowing concurrent reads from multiple render frames without blocking on each other.

§Examples

use clawless_core::event::{Event, event_channel};
use clawless_tui::projection::Projection;

let (sender, receiver) = event_channel();
let projection = Projection::new(receiver);

sender.send(Event::Message("processing".to_string()))
    .await
    .expect("should send");
drop(sender);

// Wait for the drain task, which finishes once the dropped sender closes the channel
while !projection.is_complete() {
    tokio::task::yield_now().await;
}

let messages = projection.messages();
assert_eq!(messages.len(), 1);

Implementations§

Source§

impl Projection

Source

pub fn new(receiver: EventReceiver) -> Self

Creates a new projection that drains events from the given receiver

Spawns a background task that reads events from receiver, translates each into an Entry, and appends it to internal storage. The task runs until the event channel closes, at which point it marks the projection as complete.

The returned projection is immediately ready to query. Early queries return empty results until events arrive.

§Panics

Panics if called outside of a Tokio runtime.

§Examples
use clawless_core::event::event_channel;
use clawless_tui::projection::Projection;

let (_sender, receiver) = event_channel();
let projection = Projection::new(receiver);

assert!(projection.entries().is_empty());
Source

pub fn entries(&self) -> Vec<Entry>

Returns all accumulated entries in receive order

Returns a cloned snapshot of the entry list. The snapshot is consistent: it reflects all events drained up to the moment the read lock is acquired.

§Panics

Panics if the internal lock is poisoned.

Source

pub fn messages(&self) -> Vec<Entry>

Returns accumulated message entries only

Equivalent to calling entries and filtering to Entry::Message variants.

§Panics

Panics if the internal lock is poisoned.

Source

pub fn details(&self) -> Vec<Entry>

Returns accumulated detail entries only

Equivalent to calling entries and filtering to Entry::Detail variants.

§Panics

Panics if the internal lock is poisoned.

Source

pub fn artifacts(&self) -> Vec<Entry>

Returns accumulated artifact entries only

Equivalent to calling entries and filtering to Entry::Artifact variants.

§Panics

Panics if the internal lock is poisoned.

Source

pub fn is_complete(&self) -> bool

Reports whether the event stream has closed and all buffered events have been drained

Returns true once all EventSenders have been dropped and the drain task has processed every buffered event. Before that point, returns false.

§Panics

Panics if the internal lock is poisoned.

Trait Implementations§

Source§

impl Debug for Projection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.