tengri/input/src/input_command.rs
unspeaker 35ad371205
Some checks are pending
/ build (push) Waiting to run
input: add InputMap; dsl/output/tui: Atom->Dsl
2025-04-28 04:55:27 +03:00

21 lines
533 B
Rust

use crate::*;
pub trait Command<S>: Send + Sync + Sized {
fn execute (self, state: &mut S) -> Perhaps<Self>;
fn delegate <T> (self, state: &mut S, wrap: impl Fn(Self)->T) -> Perhaps<T>
where Self: Sized
{
Ok(self.execute(state)?.map(wrap))
}
}
impl<S, T: Command<S>> Command<S> for Option<T> {
fn execute (self, _: &mut S) -> Perhaps<Self> {
Ok(None)
}
fn delegate <U> (self, _: &mut S, _: impl Fn(Self)->U) -> Perhaps<U>
where Self: Sized
{
Ok(None)
}
}