#How would you turn this a function into a macro for f64, i64, and u64?

1 messages · Page 1 of 1 (latest)

ancient narwhal
#
pub fn json_to_vector(json: Value) -> Result<Vector2<f64>, simple_error::SimpleError> {
    Ok(
        Vector2::new(
        match json["x"].as_f64() { // as_f64, as_i64, and as_u64 are implemented
            Some(v) => v,
            None => return Err(simple_error::SimpleError::new("function json_to_vector failed to get x value from json".to_owned()))
        },
        match json["y"].as_f64() { // as_f64, as_i64, and as_u64 are implemented
            Some(v) => v,
            None => return Err(simple_error::SimpleError::new("function json_to_vector failed to get y value from json".to_owned()))
        }
        )
    )
}
#

This function is a standalone function.