fn from_json()

in binding-rust/src/lib.rs [26:51]


	fn from_json(info: &Value) -> Space {
		match info.find("name").unwrap().as_str().unwrap() {
			"Discrete" => {
				let n = info.find("n").unwrap().as_u64().unwrap();
				Space::DISCRETE{n: n}
			},
			"Box" => {
				let shape = info.find("shape").unwrap().as_array().unwrap()
								.into_iter().map(|x| x.as_u64().unwrap())
								.collect::<Vec<_>>();


				let high = info.find("high").unwrap().as_array().unwrap()
							   .into_iter().map(|x| x.as_f64().unwrap())
							   .collect::<Vec<_>>();
							   
				let low = info.find("low").unwrap().as_array().unwrap()
							  .into_iter().map(|x| x.as_f64().unwrap())
							  .collect::<Vec<_>>();

				Space::BOX{shape: shape, high: high, low: low}
			},
			"Tuple" => panic!("Parsing for Tuple spaces is not yet implemented"),
			e @ _ => panic!("Unrecognized space name: {}", e)
		}
	}