Macro errors - unexpected end of invocation & missing tokens

I'm currently writing a program that deserializes a file into a JSON file as a proof-of-concept.

Trying to add my_child_property to the Properties hashmap would error out the error in the title.

I'm a bit stumped on this error. How would I satisfy the macro so that it wouldn't error out?

#![allow(non_snake_case)]

#[macro_use] extern crate maplit;

use serde::{Serialize};
use std::collections::HashMap;
use serde_json;
use rbx_dom_weak::RbxValue;

#[derive(Debug, Serialize)]
struct Model {
    Name: String,
    ClassName: String,
    Children: Vec<Child>
}

#[derive(Debug, Serialize)]
struct Child {
    Name: String,
    ClassName: String,
    Properties: HashMap<String, Property>
}

#[derive(Debug, Serialize)]
struct Property {
    Type: String,
    Value: RbxValue
}


fn main() {
    let my_child_property = Property {
        Type: "Vector3".to_owned(),
        Value: RbxValue::Vector3 {
            value: [5.0, 5.0, 5.0]
        }
    };

    let my_child = Child {
        Name: "Child".to_owned(),
        ClassName: "Part".to_owned(),
        Properties: hashmap! {
            "Size": my_child_property /*
                unexpected end of macro invocation
                missing tokens in macro arguments
            */
        }
    };

    let my_model = Model {
        Name: "CoolModel".to_owned(),
        ClassName: "Folder".to_owned(),
        Children: vec![
            my_child
        ]
    }; 

    let json_dump = serde_json::to_string_pretty(&my_model).expect("Couldn't parse JSON into string dump");
    println!("{}", json_dump)
}

::maplit::hashmap! uses => to separate the key from the value :wink:

    let my_child = Child {
        Name: "Child".to_owned(),
        ClassName: "Part".to_owned(),
        Properties: hashmap! {
-           "Size": my_child_property /*
+           "Size" => my_child_property /*
                unexpected end of macro invocation
                missing tokens in macro arguments
            */
        }
    };
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.