yarnspinner_runtime/markup/parsed_markup/
markup_value.rs1use crate::prelude::*;
5use core::fmt::Display;
6
7#[derive(Debug, Clone, PartialEq)]
12#[cfg_attr(feature = "bevy", derive(Reflect))]
13#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14#[cfg_attr(feature = "bevy", reflect(Debug, PartialEq))]
15#[cfg_attr(
16 all(feature = "bevy", feature = "serde"),
17 reflect(Serialize, Deserialize)
18)]
19pub enum MarkupValue {
20 Integer(u32),
22 Float(f32),
24 String(String),
26 Bool(bool),
28}
29
30impl MarkupValue {
31 pub fn type_name(&self) -> &'static str {
33 match self {
34 MarkupValue::Integer(_) => "Integer",
35 MarkupValue::Float(_) => "Float",
36 MarkupValue::String(_) => "String",
37 MarkupValue::Bool(_) => "Bool",
38 }
39 }
40}
41
42impl Display for MarkupValue {
43 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44 match self {
45 MarkupValue::Integer(i) => write!(f, "{i}"),
46 MarkupValue::Float(fl) => write!(f, "{fl}"),
47 MarkupValue::String(s) => write!(f, "{s}"),
48 MarkupValue::Bool(b) => write!(f, "{b}"),
49 }
50 }
51}
52
53impl From<String> for MarkupValue {
54 fn from(s: String) -> Self {
55 MarkupValue::String(s)
56 }
57}
58
59impl From<&str> for MarkupValue {
60 fn from(s: &str) -> Self {
61 MarkupValue::String(s.to_string())
62 }
63}
64
65impl From<u32> for MarkupValue {
66 fn from(i: u32) -> Self {
67 MarkupValue::Integer(i)
68 }
69}
70
71impl From<f32> for MarkupValue {
72 fn from(f: f32) -> Self {
73 MarkupValue::Float(f)
74 }
75}
76
77impl From<bool> for MarkupValue {
78 fn from(b: bool) -> Self {
79 MarkupValue::Bool(b)
80 }
81}