utility_macros_internals/union/static_str_union.rs
1use static_assertions::assert_obj_safe;
2
3use crate::{error::Result, union::union::Union};
4
5assert_obj_safe!(StaticStrUnion);
6
7/// A trait for representing a `&'static str` union
8/// Don't implement this trait manually, use the `union` macro instead
9pub trait StaticStrUnion: Union {
10 /// Return all variants as `&'static str`
11 fn strs() -> Vec<&'static str>
12 where
13 Self: Sized;
14
15 /// Returns the `&'static str` representation of the variant
16 fn as_str(&self) -> &'static str;
17
18 /// Tries to convert a `&'static str` to `Self`
19 fn try_from_str(value: &str) -> Result<Self>
20 where
21 Self: Sized;
22}
23
24impl<T> Union for T where T: StaticStrUnion {}