Skip to main content

Reacting

Trait Reacting 

Source
pub trait Reacting: Sized + 'static {
    type Kept: 'static;

    // Required methods
    async fn hear(&mut self, said: Message) -> Result<(), Failure>;
    async fn answer(&mut self, asked: Message) -> Result<Answer, Failure>;
    async fn finish(self) -> Result<Self::Kept, Failure>;
}
Expand description

One shell’s reaction, for as long as that shell can speak.

It runs as a task of its own, so it owns what it holds ('static) and is never sent to another thread. Awaiting inside a method yields to the other shells’ tasks; synchronous work blocks them for its duration.

heara Message nobody is waiting on
answerone the shell blocks on; the task writes the Answer back to it
finishwhat is left, which lands in Attended::kept

No method has a default body. The two implementations below are the templates to copy.

Required Associated Types§

Source

type Kept: 'static

What is left when the shell can no longer speak. Self where nothing is released at the end.

Required Methods§

Source

async fn hear(&mut self, said: Message) -> Result<(), Failure>

A Failure from this or answer ends the conversation: under Driving the subject is killed and the run yields that reason.

Source

async fn answer(&mut self, asked: Message) -> Result<Answer, Failure>

An answer is a command, and every answer is the same kind of thing. Saying no is a command that returns non-zero — Answer::unknown for a word this rig has no answer for.

Source

async fn finish(self) -> Result<Self::Kept, Failure>

The conversation is over; release what this held.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Reacting for ()

A reaction that keeps nothing and answers nothing.

Source§

type Kept = ()

Source§

async fn hear(&mut self, _said: Message) -> Result<(), Failure>

Source§

async fn answer(&mut self, _asked: Message) -> Result<Answer, Failure>

Source§

async fn finish(self) -> Result<Self, Failure>

Source§

impl Reacting for Vec<Message>

A reaction that keeps every message, and has no answer to any of them.

Source§

type Kept = Vec<Message>

Source§

async fn hear(&mut self, said: Message) -> Result<(), Failure>

Source§

async fn answer(&mut self, asked: Message) -> Result<Answer, Failure>

Source§

async fn finish(self) -> Result<Self, Failure>

Implementors§