mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
21 lines
533 B
Rust
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)
|
|
}
|
|
}
|