raystack_core/
xstr.rs

1/// A Haystack XStr.
2#[derive(Clone, Debug, Eq, PartialEq)]
3pub struct Xstr {
4    type_name: String,
5    value: String,
6}
7
8impl Xstr {
9    /// Create a new `Xstr`.
10    ///
11    /// # Example
12    /// ```rust
13    /// use raystack_core::Xstr;
14    /// let my_xstr = Xstr::new("Color".to_string(), "red".to_string());
15    /// ```
16    pub fn new(type_name: String, value: String) -> Self {
17        Self { type_name, value }
18    }
19
20    pub fn type_name(&self) -> &str {
21        &self.type_name
22    }
23
24    pub fn value(&self) -> &str {
25        &self.value
26    }
27
28    /// Return this `Xstr` as Axon code.
29    pub fn to_axon_code(&self) -> String {
30        format!("xstr(\"{}\", \"{}\")", self.type_name(), self.value())
31    }
32}
33
34impl std::fmt::Display for Xstr {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        write!(f, "{}(\"{}\")", self.type_name(), self.value())
37    }
38}