feat: complete refactor of all data structures and fix serialization
This commit is contained in:
1 parent
f2d8688c0c
commit
c573263f48
4 files changed
+28
-36
No files matched your search
@@ -9,7 +9,7 @@ pub enum ValueType {
|
||||
/// Indicates a `String` value.
|
||||
String(Option<String>),
|
||||
/// Indicates an `i32` value.
|
||||
Number(Option<i32>),
|
||||
Number(Option<String>),
|
||||
/// Indicates a `Vec<T>`, where `T` can be any other `ValueType`.
|
||||
List(Option<Vec<ValueType>>),
|
||||
}
|
||||
@@ -35,7 +35,7 @@ impl ValueType {
|
||||
}
|
||||
|
||||
/// Attempts to get this value as an `i32`.
|
||||
pub fn as_number(&self) -> Result<Option<i32>, Self> {
|
||||
pub fn as_number(&self) -> Result<Option<String>, Self> {
|
||||
if let ValueType::Number(v) = self {
|
||||
Ok(v.clone())
|
||||
} else {
|
||||
@@ -69,7 +69,7 @@ impl Display for ValueType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let str = match self {
|
||||
ValueType::String(s) => s.clone().unwrap_or("".to_owned()),
|
||||
ValueType::Number(n) => n.unwrap_or(0).to_string(),
|
||||
ValueType::Number(n) => n.clone().unwrap_or("".to_owned()),
|
||||
ValueType::List(l) => format!("{l:?}"),
|
||||
};
|
||||
write!(f, "{}", str)
|
||||
|
||||
@@ -44,7 +44,7 @@ pub fn OutlinedTextField(
|
||||
// If the number parses, Some(num), else None, but we want to keep the value that's
|
||||
// in the text field at this point, just set the error.
|
||||
console_log(format!("Parsing {to_parse} to a number").as_str());
|
||||
match to_parse.parse::<i32>().map(|n| ValueType::Number(Some(n))) {
|
||||
match to_parse.parse::<i32>().map(|n| ValueType::Number(Some(n.to_string()))) {
|
||||
Ok(value_type) => {
|
||||
error.set(false);
|
||||
value.set(value_type.clone());
|
||||
|
||||
Reference in new issue
Block a user