Skip to main content

ferroui_controls/application_lifetimes/
i_application_lifetime.rs

1use super::{
2    IActivityApplicationLifetime, IControlledApplicationLifetime, ISetupApplicationLifetime,
3    ISingleViewApplicationLifetime,
4};
5use std::any::Any;
6
7/// The lifetime of an application: the object that decides when the
8/// application starts and ends and what its main view is.
9///
10/// The more specific lifetime contracts are reached through the `as_*`
11/// methods, which a lifetime overrides for every contract it implements, or
12/// through [`as_any`](Self::as_any) for a concrete lifetime type.
13pub trait IApplicationLifetime {
14    /// The lifetime as its concrete type.
15    fn as_any(&self) -> &dyn Any;
16
17    /// The lifetime as a controlled lifetime, if it is one.
18    fn as_controlled_application_lifetime(&self) -> Option<&dyn IControlledApplicationLifetime> {
19        None
20    }
21
22    /// The lifetime as a single view lifetime, if it is one.
23    fn as_single_view_application_lifetime(&self) -> Option<&dyn ISingleViewApplicationLifetime> {
24        None
25    }
26
27    /// The lifetime as a single top-level lifetime, if it is one.
28    fn as_single_top_level_application_lifetime(&self) -> Option<&dyn super::ISingleTopLevelApplicationLifetime> {
29        None
30    }
31
32    /// The lifetime as an activity lifetime, if it is one.
33    fn as_activity_application_lifetime(&self) -> Option<&dyn IActivityApplicationLifetime> {
34        None
35    }
36
37    /// The lifetime as a lifetime that takes part in the setup of the
38    /// application, if it is one.
39    fn as_setup_application_lifetime(&self) -> Option<&dyn ISetupApplicationLifetime> {
40        None
41    }
42
43    /// The lifetime as a classic desktop style lifetime, if it is one.
44    fn as_classic_desktop_style_application_lifetime(
45        &self,
46    ) -> Option<&dyn super::IClassicDesktopStyleApplicationLifetime> {
47        None
48    }
49}
50
51/// Handles compare by identity (reference equality), so that they can be
52/// held in property and untyped values.
53impl PartialEq for dyn IApplicationLifetime {
54    #[inline]
55    fn eq(&self, other: &Self) -> bool {
56        std::ptr::addr_eq(self as *const Self, other as *const Self)
57    }
58}