Skip to main content

matchmaker/utils/
types.rs

1use std::borrow::Cow;
2
3use cli_boilerplate_automation::define_either;
4use ratatui::text::Text;
5
6use crate::utils::text::text_to_string;
7
8define_either! {
9    #[derive(serde::Serialize, serde::Deserialize)]
10    #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
11    pub enum Either<L, R = L> {
12        Left,
13        Right
14    }
15}
16
17impl Either<String, Text<'static>> {
18    pub fn to_cow(&self) -> Cow<'_, str> {
19        match self {
20            Either::Left(s) => Cow::Borrowed(s),
21            Either::Right(t) => Cow::Owned(text_to_string(t)),
22        }
23    }
24
25    pub fn to_text(self) -> Text<'static> {
26        match self {
27            Either::Left(s) => Text::from(s),
28            Either::Right(t) => t,
29        }
30    }
31}