1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Key types and functions for creating actions, components, packages, and themes.

use crate::util;

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;

    fn as_any_mut(&mut self) -> &mut dyn Any;
}

impl<T: Any> AnyBase for T {
    #[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;

// API to build new components.
pub mod component;

// API to add new features with packages.
pub mod package;

// API to add new layouts with themes.
pub mod theme;