MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / serde_from_str

Function serde_from_str

aiscript-vm/src/stdlib/serde.rs:30–48  ·  view source on GitHub ↗
(
    state: &mut State<'gc>,
    args: Vec<Value<'gc>>,
)

Source from the content-addressed store, hash-verified

28}
29
30fn serde_from_str<'gc>(
31 state: &mut State<'gc>,
32 args: Vec<Value<'gc>>,
33) -> Result<Value<'gc>, VmError> {
34 if args.is_empty() || args.len() > 1 {
35 return Err(VmError::RuntimeError(
36 "from_str() takes exactly 1 argument".into(),
37 ));
38 }
39
40 let json_str = string_arg!(&args, 0, "from_str")?;
41
42 // Parse JSON string into serde_json::Value
43 let parsed = serde_json::from_str(json_str.to_str().unwrap())
44 .map_err(|e| VmError::RuntimeError(format!("Failed to parse JSON: {}", e)))?;
45
46 // Convert serde_json::Value to AIScript Value
47 Ok(Value::from_serde_value(state.get_context(), &parsed))
48}
49
50fn serde_to_str<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {
51 let (positional, keyword) = extract_keyword_args(&args)?;

Callers

nothing calls this directly

Calls 4

RuntimeErrorClass · 0.85
lenMethod · 0.80
to_strMethod · 0.80
get_contextMethod · 0.80

Tested by

no test coverage detected