mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-07-17 15:56:57 +02:00
This commit is contained in:
parent
c0d8c5f1bb
commit
a06ea2ac13
5 changed files with 67 additions and 58 deletions
43
src/lib.rs
43
src/lib.rs
|
|
@ -25,10 +25,10 @@ pub(crate) use ::{
|
|||
|
||||
#[cfg(feature = "lang")] pub extern crate dizzle as lang;
|
||||
#[cfg(feature = "lang")] pub use ::dizzle::{self, Usually, Perhaps, impl_default};
|
||||
#[cfg(feature = "lang")] pub mod eval;
|
||||
|
||||
#[cfg(feature = "time")] pub mod time;
|
||||
|
||||
#[cfg(feature = "play")] pub mod play;
|
||||
#[cfg(feature = "play")] pub mod exit;
|
||||
#[cfg(feature = "play")] pub mod task;
|
||||
|
||||
|
|
@ -39,6 +39,7 @@ pub(crate) use ::{
|
|||
#[cfg(feature = "draw")] pub mod draw;
|
||||
#[cfg(feature = "draw")] pub mod space;
|
||||
#[cfg(feature = "draw")] pub mod color;
|
||||
|
||||
#[cfg(feature = "text")] pub mod text;
|
||||
#[cfg(feature = "term")] pub mod term;
|
||||
#[cfg(feature = "term")] pub mod keys;
|
||||
|
|
@ -75,3 +76,43 @@ pub(crate) use ::{
|
|||
}
|
||||
};
|
||||
);
|
||||
|
||||
/// Define an enum containing commands, and implement [Command] trait for over given `State`.
|
||||
#[macro_export] macro_rules! def_command (
|
||||
($Command:ident: |$state:ident: $State:ty| {
|
||||
// FIXME: support attrs (docstrings)
|
||||
$($Variant:ident$({$($arg:ident:$Arg:ty),+ $(,)?})?=>$body:expr),* $(,)?
|
||||
})=>{
|
||||
#[derive(Debug)] pub enum $Command {
|
||||
// FIXME: support attrs (docstrings)
|
||||
$($Variant $({ $($arg: $Arg),* })?),*
|
||||
}
|
||||
impl ::tengri::dizzle::Act<$State> for $Command {
|
||||
fn act (&self, $state: &mut $State) -> Perhaps<Self> {
|
||||
match self {
|
||||
$(Self::$Variant $({ $($arg),* })? => $body,)*
|
||||
_ => unimplemented!("Act<{}>: {self:?}", stringify!($State)),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/// Implement [Handle] for given `State` and `handler`.
|
||||
#[macro_export] macro_rules! impl_handle {
|
||||
//(|$self:ident:$State:ty,$input:ident|$handler:expr) => {
|
||||
//impl<E: Engine> ::tengri::Handle<E> for $State {
|
||||
//fn handle (&mut $self, $input: &E) -> Perhaps<E::Handled> {
|
||||
//$handler
|
||||
//}
|
||||
//}
|
||||
//};
|
||||
($E:ty: |$self:ident:$State:ty,$input:ident|$handler:expr) => {
|
||||
//impl ::tengri::Handle<$E> for $State {
|
||||
//fn handle (&mut $self, $input: &$E) ->
|
||||
//Perhaps<<$E as ::tengri::Input>::Handled>
|
||||
//{
|
||||
//$handler
|
||||
//}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue