Hello there!
Thank you for taking the time to check my question out but being a complete Rust newbie, I’m struggling with a simple task and I can not seem to get it working, even after going through Rust’s documentation.
My question regards iterating through the output of hdk::query_result
. I want to retrieve entries from my local chain of a certain type (Message, in my case). It is that simple. I have the following code, since I am only interested in the Entries field of QueryResults.
pub fn test() -> ZomeApiResult<Vec<Message>> {
let mut return_vector = Vec::new();
if let QueryResult::Entries(query_results) = hdk::query_result(
MESSAGE_ENTRY_NAME.into(),
QueryArgsOptions{ entries: true, headers: false, ..Default::default()}
)? {
for (_, Entry::App(_, entry_value)) in query_results.iter() {
let message = Message::try_from(entry_value)?;
return_vector.push(message)
}
} else {
unreachable!()
}
Ok(return_vector)
}
But I have the following error:
error[E0005]: refutable pattern in `for` loop binding: `&(_, Dna(_))`, `&(_, AgentId(_))`, `&(_, Deletion(_))` and 7 more not covered
--> src/message/handlers.rs:62:13
|
62 | for (_, Entry::App(_, entry_value)) in query_results.iter() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ patterns `&(_, Dna(_))`, `&(_, AgentId(_))`, `&(_, Deletion(_))` and 7 more not covered
I understand that I should match every pattern but is there a way to not do it? It seems that doing so makes the code quite confusing. I am only interested in the entry_value
and return a vector with it, after all, right?
Any suggestions would be appreciated, thank you