[BigQuery] How to instantiate request #327
-
Hello! I am trying to use the google-apis-rs/gen/bigquery2/src/api.rs Line 4841 in beb110a This requires me to instantiate a google-apis-rs/gen/bigquery2/src/api.rs Line 3093 in beb110a This requires me to instantiate a vector of google-apis-rs/gen/bigquery2/src/api.rs Line 3853 in beb110a This require me to provide a google-apis-rs/gen/bigquery2/src/api.rs Line 2035 in beb110a But it has private members and no initializer that I can see. How can I create it? What am I missing? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Thanks for letting me know in such an easy to follow fashion! Apologies for turning this legitimate issue into a discussion, #328 is the re-created issue from it to which you might want to subscribe for updates. That said, to me it appears that the tuple-structs the system generates are generally lacking the My suggestion is to vendor the code, make the needed adjustments, and see if the valid request can be made like that. I have made the necessary adjustment to the generator and regenerated the code so you can take it from |
Beta Was this translation helpful? Give feedback.
-
As always, it's a pleasure interacting with you. I can confirm that the new version currently on It is a bit unwieldy however. I have something like #[derive(Serialize)]
struct Event {
// ... various fields
} RIght now I am keeping a buffer of them ready to be sent let mut buffer: Vec<JsonObject> = Vec::with_capacity(CAPACITY);
loop {
match channel.recv() {
Some(event) => {
// here I have to do some work
let values: HashMap<String, JsonValue> = serde_json::to_value(event)
.unwrap()
.as_object()
.unwrap()
.into_iter()
.map(|(key, value)| (key.clone(), JsonValue(value.clone())))
.collect();
buffer.push(JsonObject(Some(values)));
}
_ => {}
}
// ....
} I don't have many ideas on how to make it better :( |
Beta Was this translation helpful? Give feedback.
-
I played around a little bit and I think that it should be possible to add something like: impl<T> TryFrom<T> for JsonObject where T: Serialize {
type Error = serde_json::Error;
fn try_from(value: T) -> Result<Self, Self::Error> {
let values_map: HashMap<String, JsonValue> = serde_json::to_value(value)?
.as_object()
.ok_or_else(|| {
serde_json::Error::custom("value needs to be representable as a JSON object")
})?
.into_iter()
.map(|(key, value)| (key.clone(), JsonValue(value.clone())))
.collect();
Ok(JsonObject(Some(values_map)))
}
} but the compiler complains about a duplicated conformance, and I cannot figure out why 😢 |
Beta Was this translation helpful? Give feedback.
-
I think something went wrong somewhere with the release... I can see that the regeneration commit (77f097d) bumped the version to Am I missing something, or are things really broken? |
Beta Was this translation helpful? Give feedback.
Thanks for letting me know in such an easy to follow fashion! Apologies for turning this legitimate issue into a discussion, #328 is the re-created issue from it to which you might want to subscribe for updates.
That said, to me it appears that the tuple-structs the system generates are generally lacking the
pub
specifier and I couldn't think of any other reason than oversight.My suggestion is to vendor the code, make the needed adjustments, and see if the valid request can be made like that. I have made the necessary adjustment to the generator and regenerated the code so you can take it from
main
. Please let me know in the issue if this works for you, and I could make a new release for…