pub struct Output { /* private fields */ }Expand description
Command output interface that wraps an event channel sender
Output provides typed methods for each event kind, decoupling commands from the event channel
API. Commands call message, detail, or artifact to emit events; the Presenter
consumes them for rendering.
Output is cheaply clonable. Cloning an Output produces another handle to the same
underlying channel, not an independent channel.
§Examples
use clawless_core::event::event_channel;
use clawless_core::output::Output;
let (sender, mut receiver) = event_channel();
let output = Output::new(sender);
output.message("hello").await.expect("should send");Implementations§
Source§impl Output
impl Output
Sourcepub fn new(sender: EventSender) -> Self
pub fn new(sender: EventSender) -> Self
Creates a new Output wrapping the given event sender
§Examples
use clawless_core::event::event_channel;
use clawless_core::output::Output;
let (sender, _receiver) = event_channel();
let output = Output::new(sender);Sourcepub async fn message(&self, message: impl Display) -> Result<(), SendError>
pub async fn message(&self, message: impl Display) -> Result<(), SendError>
Sends an informational message event
Converts the value to a string via Display and sends it as an Event::Message.
§Errors
Returns SendError if the EventReceiver has been dropped.
§Examples
use clawless_core::event::event_channel;
use clawless_core::output::Output;
let (sender, _receiver) = event_channel();
let output = Output::new(sender);
output.message("processing files").await.expect("should send");
output.message(format!("found {} items", 42)).await.expect("should send");Sourcepub async fn detail(&self, detail: impl Display) -> Result<(), SendError>
pub async fn detail(&self, detail: impl Display) -> Result<(), SendError>
Sends a supplementary detail event
Converts the value to a string via Display and sends it as an Event::Detail.
Details carry lower-priority information that the Presenter may suppress at default
verbosity.
§Errors
Returns SendError if the EventReceiver has been dropped.
§Examples
use clawless_core::event::event_channel;
use clawless_core::output::Output;
let (sender, _receiver) = event_channel();
let output = Output::new(sender);
output.detail("reading config from ~/.config/app.toml").await.expect("should send");Sourcepub async fn artifact<T>(&self, value: T) -> Result<(), SendError>
pub async fn artifact<T>(&self, value: T) -> Result<(), SendError>
Sends a structured artifact event
Wraps the value in a Box and sends it as an Event::Artifact. The value must
implement Display (for text rendering), Serialize (for JSON rendering), and
Debug (for diagnostics).
§Errors
Returns SendError if the EventReceiver has been dropped.
§Examples
use std::fmt;
use serde::Serialize;
use clawless_core::event::event_channel;
use clawless_core::output::Output;
#[derive(Clone, Debug, Serialize)]
struct UserCount {
count: usize,
}
impl fmt::Display for UserCount {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} users", self.count)
}
}
let (sender, _receiver) = event_channel();
let output = Output::new(sender);
output.artifact(UserCount { count: 42 }).await.expect("should send");