oxidecomputer / typify

compiler from JSON Schema into idiomatic Rust types
Apache License 2.0
418 stars 57 forks source link

How to use builder pattern? #581

Closed maaft closed 5 months ago

maaft commented 5 months ago

I see that I can call builder::GeneratedStruct::builder() to receive a builder that I can use to set different fields.

But how can I then actually build it to get GeneratedStruct out of it (not builder::GeneratedStruct) ?

maaft commented 5 months ago

Never mind, I got it.

For anyone wondering:

// build
let builder = GeneratedStruct::builder().id("id");
// convert to actual struct. Might error, that's why we must use try_from
let s = GeneratedStruct::try_from(builder)?;