mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-01-31 10:56:41 +01:00
This commit is contained in:
parent
d06e1c41f8
commit
8a5bc7b6ea
4 changed files with 67 additions and 36 deletions
|
|
@ -19,6 +19,37 @@ pub trait Input: Sized {
|
|||
fn done (&self);
|
||||
}
|
||||
|
||||
/// 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),*) })*
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
flex_trait_mut!(Handle <E: Input> {
|
||||
fn handle (&mut self, _input: &E) -> Perhaps<E::Handled> {
|
||||
Ok(None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue