pub fn parse(value: &str, ty: &AlgebraicType) -> Result<AlgebraicValue, ErrorVm>Expand description
Parse a &str into AlgebraicValue using the supplied AlgebraicType.
use spacetimedb_sats::{AlgebraicType, AlgebraicValue};
use spacetimedb_vm::errors::ErrorLang;
use spacetimedb_vm::ops::parse::parse;
assert_eq!(parse("1", &AlgebraicType::I32).map_err(ErrorLang::from), Ok(AlgebraicValue::I32(1)));
assert_eq!(parse("true", &AlgebraicType::Bool).map_err(ErrorLang::from), Ok(AlgebraicValue::Bool(true)));
assert_eq!(parse("1.0", &AlgebraicType::F64).map_err(ErrorLang::from), Ok(AlgebraicValue::F64(1.0f64.into())));
assert_eq!(parse("Player", &AlgebraicType::simple_enum(["Player"].into_iter())).map_err(ErrorLang::from), Ok(AlgebraicValue::enum_simple(0)));
assert!(parse("bananas", &AlgebraicType::I32).is_err());