fn populate_toml_dictionary(
	toml: &Value,
	dictionary: &mut Dictionary,
	table: &toml::map::Map<std::string::String, Value>,
) {
	for (key, value) in table {
		let field_type = value.type_str();
		match field_type {
			"table" => {
				let sub_dic = &mut Dictionary::new();
				let new_table = table[key]
					.as_table()
					.expect("Unable to cast value to table");
				populate_toml_dictionary(toml, sub_dic, new_table);
				dictionary.set(&Variant::from_str(key), &Variant::from_dictionary(sub_dic));
			}
			"array" => {
				let mut dictionary_arr = VariantArray::new();
				let toml_arr = table[key]
					.as_array()
					.expect("Unable to cast value to array");
				for i in toml_arr {
					let sub_dic = &mut Dictionary::new();
					populate_toml_dictionary(toml, sub_dic, i.as_table().unwrap());
					dictionary_arr.push(&Variant::from_dictionary(sub_dic));
				}
				dictionary.set(
					&Variant::from_str(key),
					&Variant::from_array(&dictionary_arr),
				)
			}
			"integer" => dictionary.set(
				&Variant::from_str(key),
				&Variant::from_i64(value.as_integer().expect("Unable to cast value to integer")),
			),
			"string" => {
				let value_as_str = value.as_str().expect("Unable to cast value to string");
				// A simple check to that we can avoid the cost of regex if we don't need to is to check if the string contains a parenthesis.
				if value_as_str.contains("(") {
					encode_godot_types(dictionary, key, value_as_str);
				} else {
					dictionary.set(&Variant::from_str(key), &Variant::from_str(value_as_str))
				}
			}
			"float" => dictionary.set(
				&Variant::from_str(key),
				&Variant::from_f64(value.as_float().expect("Unable to cast value to float")),
			),
			"boolean" => dictionary.set(
				&Variant::from_str(key),
				&Variant::from_bool(value.as_bool().expect("Unable to cast value to bool")),
			),
			"datetime" => dictionary.set(
				&Variant::from_str(key),
				&Variant::from_str(
					value
						.as_datetime()
						.expect("Unable to cast value to float")
						.to_string(),
				),
			),
			_ => (),
		}
	}
}
/// Populates a dictonary with the parsed values of the toml table provided.
///
/// If a value contains a string, it is further parsed by convert_godot_types which checks to see if the string is a Godot type and then performs
/// the necessary conversions on it and adds it to the dictionary.
///
/// # Arguments
///
/// `toml` - The parsed toml.
/// `dictionary` - The dictionary to populate.
/// `table` - The Table from the parsed toml.
Populates a dictonary with the parsed values of the toml table provided.
If a value contains a string, it is further parsed by convert_godot_types which checks to see if the string is a Godot type and then performs
the necessary conversions on it and adds it to the dictionary.
Populates a dictonary with the parsed values of the toml table provided . If a value contains a string it is further parsed by convert_godot_types which checks to see if the string is a Godot type and then performs the necessary conversions on it and adds it to the dictionary .
fn populate_toml_dictionary(
	toml: &Value,
	dictionary: &mut Dictionary,
	table: &toml::map::Map<std::string::String, Value>,
) {
	for (key, value) in table {
		let field_type = value.type_str();
		match field_type {
			"table" => {
				let sub_dic = &mut Dictionary::new();
				let new_table = table[key]
					.as_table()
					.expect("Unable to cast value to table");
				populate_toml_dictionary(toml, sub_dic, new_table);
				dictionary.set(&Variant::from_str(key), &Variant::from_dictionary(sub_dic));
			}
			"array" => {
				let mut dictionary_arr = VariantArray::new();
				let toml_arr = table[key]
					.as_array()
					.expect("Unable to cast value to array");
				for i in toml_arr {
					let sub_dic = &mut Dictionary::new();
					populate_toml_dictionary(toml, sub_dic, i.as_table().unwrap());
					dictionary_arr.push(&Variant::from_dictionary(sub_dic));
				}
				dictionary.set(
					&Variant::from_str(key),
					&Variant::from_array(&dictionary_arr),
				)
			}
			"integer" => dictionary.set(
				&Variant::from_str(key),
				&Variant::from_i64(value.as_integer().expect("Unable to cast value to integer")),
			),
			"string" => {
				let value_as_str = value.as_str().expect("Unable to cast value to string");
				// A simple check to that we can avoid the cost of regex if we don't need to is to check if the string contains a parenthesis.
				if value_as_str.contains("(") {
					encode_godot_types(dictionary, key, value_as_str);
				} else {
					dictionary.set(&Variant::from_str(key), &Variant::from_str(value_as_str))
				}
			}
			"float" => dictionary.set(
				&Variant::from_str(key),
				&Variant::from_f64(value.as_float().expect("Unable to cast value to float")),
			),
			"boolean" => dictionary.set(
				&Variant::from_str(key),
				&Variant::from_bool(value.as_bool().expect("Unable to cast value to bool")),
			),
			"datetime" => dictionary.set(
				&Variant::from_str(key),
				&Variant::from_str(
					value
						.as_datetime()
						.expect("Unable to cast value to float")
						.to_string(),
				),
			),
			_ => (),
		}
	}
}
fn populate_toml_dictionary ( toml : & Value , dictionary : & mut Dictionary , table : & toml :: map :: Map < std :: string :: String , Value > , ) { for ( key , value ) in table { let field_type = value . type_str ( ) ; match field_type { " " => { let sub_dic = & mut Dictionary :: new ( ) ; let new_table = table [ key ] . as_table ( ) . expect ( " " ) ; populate_toml_dictionary ( toml , sub_dic , new_table ) ; dictionary . set ( & Variant :: from_str ( key ) , & Variant :: from_dictionary ( sub_dic ) ) ; } " " => { let mut dictionary_arr = VariantArray :: new ( ) ; let toml_arr = table [ key ] . as_array ( ) . expect ( " " ) ; for i in toml_arr { let sub_dic = & mut Dictionary :: new ( ) ; populate_toml_dictionary ( toml , sub_dic , i . as_table ( ) . unwrap ( ) ) ; dictionary_arr . push ( & Variant :: from_dictionary ( sub_dic ) ) ; } dictionary . set ( & Variant :: from_str ( key ) , & Variant :: from_array ( & dictionary_arr ) , ) } " " => dictionary . set ( & Variant :: from_str ( key ) , & Variant :: from_i64 ( value . as_integer ( ) . expect ( " " ) ) , ) , " " => { let value_as_str = value . as_str ( ) . expect ( " " ) ; // A simple check to that we can avoid the cost of regex if we don't need to is to check if the string contains a parenthesis. if value_as_str . contains ( " " ) { encode_godot_types ( dictionary , key , value_as_str ) ; } else { dictionary . set ( & Variant :: from_str ( key ) , & Variant :: from_str ( value_as_str ) ) } } " " => dictionary . set ( & Variant :: from_str ( key ) , & Variant :: from_f64 ( value . as_float ( ) . expect ( " " ) ) , ) , " " => dictionary . set ( & Variant :: from_str ( key ) , & Variant :: from_bool ( value . as_bool ( ) . expect ( " " ) ) , ) , " " => dictionary . set ( & Variant :: from_str ( key ) , & Variant :: from_str ( value . as_datetime ( ) . expect ( " " ) . to_string ( ) , ) , ) , _ => ( ) , } } }
Populates a dictonary with the parsed values of the toml table provided.
Populates a dictonary with the parsed values of the toml table provided .
toml
&Value
dictionary
&mut Dictionary
table
&toml::map::Map<std::string::String, Value>