mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-07 14:16:56 +02:00
125 lines
4.8 KiB
Rust
125 lines
4.8 KiB
Rust
#![feature(anonymous_lifetime_in_impl_trait)]
|
|
//#![feature(associated_type_defaults)]
|
|
//#![feature(const_default)]
|
|
//#![feature(const_option_ops)]
|
|
#![feature(const_precise_live_drops)]
|
|
#![feature(const_trait_impl)]
|
|
//#![feature(impl_trait_in_assoc_type)]
|
|
#![feature(step_trait)]
|
|
//#![feature(trait_alias)]
|
|
//#![feature(type_alias_impl_trait)]
|
|
//#![feature(type_changing_struct_update)]
|
|
pub extern crate atomic_float;
|
|
pub extern crate palette;
|
|
pub extern crate better_panic;
|
|
pub extern crate unicode_width;
|
|
#[cfg(feature = "sing")] pub extern crate jack;
|
|
#[cfg(feature = "midi")] pub extern crate midly;
|
|
#[cfg(feature = "term")] pub extern crate ratatui;
|
|
#[cfg(feature = "term")] pub extern crate crossterm;
|
|
#[cfg(feature = "lang")] pub extern crate dizzle as lang;
|
|
#[cfg(test)] #[macro_use] pub extern crate proptest;
|
|
#[cfg(test)] pub(crate) use proptest_derive::Arbitrary;
|
|
|
|
pub(crate) use ::{
|
|
atomic_float::AtomicF64,
|
|
std::fmt::{Debug, Display},
|
|
std::ops::{Add, Sub, Mul, Div},
|
|
std::sync::{Arc, RwLock},
|
|
std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::*},
|
|
std::marker::PhantomData
|
|
};
|
|
|
|
macro_rules! features {
|
|
($($feature:literal: [ $($module:ident),* ]),*) => {
|
|
$(
|
|
$(
|
|
#[cfg(feature = $feature)] pub mod $module;
|
|
#[cfg(feature = $feature)] pub use $module::*;
|
|
)*
|
|
)*
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "lang")] pub use ::dizzle::{Usually, Perhaps, impl_default};
|
|
|
|
features! {
|
|
"lang": [ eval ],
|
|
"time": [ time ],
|
|
"play": [ exit, task ],
|
|
"sing": [ sing ],
|
|
"text": [ text ],
|
|
"term": [ term ],
|
|
"draw": [ draw ]
|
|
}
|
|
|
|
/// Define a trait an implement it for various mutation-enabled wrapper types. */
|
|
#[macro_export] macro_rules! flex_trait_mut (
|
|
($Trait:ident $(<$($A:ident:$T:ident),+>)? {
|
|
$(fn $fn:ident (&mut $self:ident $(, $arg:ident:$ty:ty)*) -> $ret:ty $body:block)*
|
|
})=>{
|
|
pub trait $Trait $(<$($A: $T),+>)? {
|
|
$(fn $fn (&mut $self $(,$arg:$ty)*) -> $ret $body)*
|
|
}
|
|
impl<$($($A: $T,)+)? _T_: $Trait $(<$($A),+>)?> $Trait $(<$($A),+>)? for &mut _T_ {
|
|
$(fn $fn (&mut $self $(,$arg:$ty)*) -> $ret { (*$self).$fn($($arg),*) })*
|
|
}
|
|
impl<$($($A: $T,)+)? _T_: $Trait $(<$($A),+>)?> $Trait $(<$($A),+>)? for Option<_T_> {
|
|
$(fn $fn (&mut $self $(,$arg:$ty)*) -> $ret {
|
|
if let Some(this) = $self { this.$fn($($arg),*) } else { Ok(None) }
|
|
})*
|
|
}
|
|
impl<$($($A: $T,)+)? _T_: $Trait $(<$($A),+>)?> $Trait $(<$($A),+>)? for ::std::sync::Mutex<_T_> {
|
|
$(fn $fn (&mut $self $(,$arg:$ty)*) -> $ret { $self.get_mut().unwrap().$fn($($arg),*) })*
|
|
}
|
|
impl<$($($A: $T,)+)? _T_: $Trait $(<$($A),+>)?> $Trait $(<$($A),+>)? for ::std::sync::Arc<::std::sync::Mutex<_T_>> {
|
|
$(fn $fn (&mut $self $(,$arg:$ty)*) -> $ret { $self.lock().unwrap().$fn($($arg),*) })*
|
|
}
|
|
impl<$($($A: $T,)+)? _T_: $Trait $(<$($A),+>)?> $Trait $(<$($A),+>)? for ::std::sync::RwLock<_T_> {
|
|
$(fn $fn (&mut $self $(,$arg:$ty)*) -> $ret { $self.write().unwrap().$fn($($arg),*) })*
|
|
}
|
|
impl<$($($A: $T,)+)? _T_: $Trait $(<$($A),+>)?> $Trait $(<$($A),+>)? for ::std::sync::Arc<::std::sync::RwLock<_T_>> {
|
|
$(fn $fn (&mut $self $(,$arg:$ty)*) -> $ret { $self.write().unwrap().$fn($($arg),*) })*
|
|
}
|
|
};
|
|
);
|
|
|
|
/// 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::lang::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
|
|
//}
|
|
//}
|
|
}
|
|
}
|