Phase 1.2-1.6: replace variables HashMap<String,String> with HashMap<String,Value>, rewrite str_to_dyn/dyn_to_str -> value_to_dynamic/dynamic_to_value, update resolve_string/evaluate_condition/is_truthy for Value

This commit is contained in:
Glint Dev
2026-07-21 20:32:29 +03:00
parent 5597f07787
commit 30cf2e5e26
7 changed files with 542 additions and 53 deletions

View File

@@ -3,11 +3,11 @@ use std::collections::HashMap;
use std::fmt;
use super::style::{ComputedStyle, StyleSheet};
use compact_str::CompactStr;
use compact_str::CompactString;
#[derive(Clone, Debug)]
pub enum Value {
Str(CompactStr),
Str(CompactString),
Int(i64),
Float(f64),
Bool(bool),
@@ -23,31 +23,31 @@ impl Value {
}
}
pub fn to_owned_string(&self) -> CompactStr {
pub fn to_owned_string(&self) -> CompactString {
match self {
Value::Str(s) => s.clone(),
Value::Int(i) => CompactStr::new(i.to_string()),
Value::Float(f) => CompactStr::new(if f.fract() == 0.0 {
Value::Int(i) => CompactString::new(i.to_string()),
Value::Float(f) => CompactString::new(if f.fract() == 0.0 {
format!("{:.1}", f)
} else {
f.to_string()
}),
Value::Bool(b) => CompactStr::new(b.to_string()),
Value::Array(a) => CompactStr::new(a.iter().map(|v| v.to_owned_string()).collect::<Vec<_>>().join(",")),
Value::None => CompactStr::new_empty(),
Value::Bool(b) => CompactString::new(b.to_string()),
Value::Array(a) => CompactString::new(a.iter().map(|v| v.to_owned_string()).collect::<Vec<_>>().join(",")),
Value::None => CompactString::new(""),
}
}
}
impl From<&str> for Value {
fn from(s: &str) -> Self {
Value::Str(CompactStr::new(s))
Value::Str(CompactString::new(s))
}
}
impl From<String> for Value {
fn from(s: String) -> Self {
Value::Str(CompactStr::new(s))
Value::Str(CompactString::new(s))
}
}
@@ -125,7 +125,7 @@ pub struct ComponentDef<'a> {
pub struct Document<'a> {
pub roots: Vec<Element<'a>>,
pub components: HashMap<String, ComponentDef<'a>>,
pub variables: HashMap<String, String>,
pub variables: HashMap<String, Value>,
pub rhei_scripts: Vec<String>,
pub stylesheet: StyleSheet,
}