google-cloud-rust icon indicating copy to clipboard operation
google-cloud-rust copied to clipboard

How to create a ARRAY<STRUCT<..>> parameters.

Open nielsbosma opened this issue 6 months ago • 2 comments

I don't get how to create ARRAY<STRUCT<..>> parameters.

struct_values of QueryParameterValue is of type Option<Box<QueryParameterValue>>, shouldn't this be a HashMap? I don't see how I can create this type of parameter?

#[derive(Debug, Clone)]
pub struct Hello {
    pub bar: String,
    pub foo: String,
}

fn main() {
    let hello_array = vec![
        Hello {
            bar: "Bar1".to_string(),
            foo: "Foo1".to_string(),
        },
        Hello {
            bar: "Bar2".to_string(),
            foo: "Foo2".to_string(),
        },
    ];

    let query_parameter = QueryParameter {
        name: Some("hello_array_param".to_string()),
        parameter_type: QueryParameterType {
            parameter_type: "ARRAY".to_string(),
            array_type: Some(Box::new(QueryParameterType {
                parameter_type: "STRUCT".to_string(),
                struct_types: Some(vec![
                    QueryParameterStructType {
                        name: Some("bar".to_string()),
                        field_type: QueryParameterType {
                            parameter_type: "STRING".to_string(),
                            array_type: None,
                            struct_types: None,
                        },
                        description: None,
                    },
                    QueryParameterStructType {
                        name: Some("foo".to_string()),
                        field_type: QueryParameterType {
                            parameter_type: "STRING".to_string(),
                            array_type: None,
                            struct_types: None,
                        },
                        description: None,
                    },
                ]),
                array_type: None,
            })),
            struct_types: None,
        },
        parameter_value: QueryParameterValue {
            value: None,
            array_values: Some(hello_array.iter().map(|hello| QueryParameterValue {
                struct_values: Some(???),
                value: None,
                array_values: None,
            }).collect()),
            struct_values: None,
        },
    };

    println!("QueryParameter: {:#?}", query_parameter);
}

nielsbosma avatar Aug 05 '24 15:08 nielsbosma