zen_rs/
components.rs

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
//! Module providing the `Components` enum and its implementations.
//!
//! The `Components` enum acts as a unified abstraction for different UI elements such as containers, text, and icons.
//! This module also includes conversions and a default implementation for `Components`.

pub mod container;
pub mod icon;
pub mod text;

pub use container::*;
pub use icon::*;
pub use text::*;

/// Represents different types of UI components.
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub enum Components {
    /// Container component.
    Container(Container),
    /// Text component.
    Text(Text),
    /// Icon component.
    Icon(Icon),
}

impl From<Container> for Components {
    /// Converts a `Container` into a `Components` variant.
    fn from(value: Container) -> Self {
        Self::Container(value)
    }
}

impl From<Text> for Components {
    /// Converts a `Text` into a `Components` variant.
    fn from(value: Text) -> Self {
        Self::Text(value)
    }
}

impl From<Icon> for Components {
    /// Converts an `Icon` into a `Components` variant.
    fn from(value: Icon) -> Self {
        Self::Icon(value)
    }
}

impl Default for Components {
    /// Returns a default `Components` variant, which is a `Container`.
    fn default() -> Self {
        Self::Container(Container::default())
    }
}