zen_rs/
components.rs

1//! Module providing the `Components` enum and its implementations.
2//!
3//! The `Components` enum acts as a unified abstraction for different UI elements such as containers, text, and icons.
4//! This module also includes conversions and a default implementation for `Components`.
5
6pub mod container;
7pub mod icon;
8pub mod text;
9
10pub use container::*;
11pub use icon::*;
12pub use text::*;
13
14/// Represents different types of UI components.
15#[derive(Debug, Clone, PartialEq, PartialOrd)]
16pub enum Components {
17    /// Container component.
18    Container(Container),
19    /// Text component.
20    Text(Text),
21    /// Icon component.
22    Icon(Icon),
23}
24
25impl From<&Components> for Components {
26    fn from(value: &Components) -> Self {
27        value.clone()
28    }
29}
30
31impl From<Container> for Components {
32    /// Converts a `Container` into a `Components` variant.
33    fn from(value: Container) -> Self {
34        Self::Container(value)
35    }
36}
37
38impl From<Text> for Components {
39    /// Converts a `Text` into a `Components` variant.
40    fn from(value: Text) -> Self {
41        Self::Text(value)
42    }
43}
44
45impl From<Icon> for Components {
46    /// Converts an `Icon` into a `Components` variant.
47    fn from(value: Icon) -> Self {
48        Self::Icon(value)
49    }
50}
51
52impl Default for Components {
53    /// Returns a default `Components` variant, which is a `Container`.
54    fn default() -> Self {
55        Self::Container(Container::default())
56    }
57}