🚧 Working on actions system
This commit is contained in:
parent
2ea0a1698e
commit
e732244a2e
15 changed files with 165 additions and 153 deletions
42
src/core.rs
42
src/core.rs
|
|
@ -6,6 +6,8 @@ use std::any::Any;
|
|||
|
||||
// Common definitions for core types.
|
||||
pub trait AnyBase: Any {
|
||||
fn type_name(&self) -> &'static str;
|
||||
|
||||
fn single_name(&self) -> &'static str;
|
||||
|
||||
fn as_any_ref(&self) -> &dyn Any;
|
||||
|
|
@ -14,19 +16,55 @@ pub trait AnyBase: Any {
|
|||
}
|
||||
|
||||
impl<T: Any> AnyBase for T {
|
||||
fn single_name(&self) -> &'static str {
|
||||
util::single_type_name::<Self>()
|
||||
#[inline(always)]
|
||||
fn type_name(&self) -> &'static str {
|
||||
std::any::type_name::<T>()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn single_name(&self) -> &'static str {
|
||||
util::single_type_name::<T>()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn as_any_ref(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AnyTo: AnyBase {
|
||||
#[inline]
|
||||
fn is<T>(&self) -> bool
|
||||
where
|
||||
T: AnyBase,
|
||||
{
|
||||
self.as_any_ref().is::<T>()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn downcast_ref<T>(&self) -> Option<&T>
|
||||
where
|
||||
T: AnyBase,
|
||||
{
|
||||
self.as_any_ref().downcast_ref()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn downcast_mut<T>(&mut self) -> Option<&mut T>
|
||||
where
|
||||
T: AnyBase,
|
||||
{
|
||||
self.as_any_mut().downcast_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized + AnyBase> AnyTo for T {}
|
||||
|
||||
// API to define functions that alter the behavior of PageTop core.
|
||||
pub mod action;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue