Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TryIntoStruct trait for ergonomic result parsing into a struct. #275

Merged
merged 2 commits into from
May 2, 2023

Conversation

obi1kenobi
Copy link
Owner

@obi1kenobi obi1kenobi commented May 1, 2023

For example:

use trustfall_core::TryIntoStruct;

#[derive(Debug, PartialEq, Eq, serde::Deserialize)]
struct Output {
    number: i64,
    text: String,
}

let results: Vec<_> = run_query()
    .expect("bad query arguments")
    .map(|v| v.try_into_struct().expect("struct definition did not match query result shape"))
    .collect();

assert_eq!(
    vec![
        Output {
            number: 42,
            text: "the answer to everything".to_string(),
        },
    ],
    results,
);

@obi1kenobi obi1kenobi changed the title Deserialize query outputs into a struct for better ergonomics. Add TryIntoStruct trait for ergonomic result parsing into a struct. May 2, 2023
@obi1kenobi obi1kenobi marked this pull request as ready for review May 2, 2023 02:48
@obi1kenobi obi1kenobi enabled auto-merge (squash) May 2, 2023 02:49
@obi1kenobi obi1kenobi disabled auto-merge May 2, 2023 02:49
@obi1kenobi obi1kenobi enabled auto-merge (squash) May 2, 2023 02:51
@obi1kenobi obi1kenobi merged commit f040345 into main May 2, 2023
11 checks passed
@obi1kenobi obi1kenobi deleted the deserialize_to_struct branch May 2, 2023 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant