Skip to main content

Output

Struct Output 

Source
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

Source

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);
Source

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");
Source

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");
Source

pub async fn artifact<T>(&self, value: T) -> Result<(), SendError>
where T: Display + Serialize + Debug + Send + Sync + 'static,

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");

Trait Implementations§

Source§

impl Clone for Output

Source§

fn clone(&self) -> Output

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Output

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.