{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreie3ppaszpr6fsxemb5quhilvwkc24xpjcdpjqoxclwo5xr2rp7m7m",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mk55o3vsvh62"
},
"path": "/t/way-to-make-a-configuration-struct-stable-across-versions/24187#post_9",
"publishedAt": "2026-04-23T02:26:49.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "malucard:\n\n> Also, obviously, an alternative way to implement this would be to use a builder. The problem is that that's way too much work. A struct would be much more ergonomic, and there should be no need to create a function for each field.\n\nI think a builder here is more ergonomic for the _user_. A builder could easily look like\n\n\n let triangle_pipeline = RasterPipelineOptions::default()\n .vertex_shader(triangle_shader_module.get(\"vertex\"))\n .fragment_shader(triangle_shader_module.get(\"fragment\"))\n .create_with(device)?;\n\n\nwhich has less nesting, avoids writing \"raster pipeline\" twice, and avoids the `Some(...)`'s which are just expressing the fact that you have chosen to include this option rather than omit it (there is almost no circumstance where you would write `RasterPipelineOptions { vertex_shader: None, ..Default::default() }`; the `Some` is not communicating valuable information, it is just visual clutter required by the direct field assignment).\n\nIt's true that _making_ the option struct function nicely as a builder would take more work, but it is also something that could be accomplished by a derive macro (at least if you're okay with `.vertex_shader(Some(...))` instead of `.vertex_shader(...)` or using attributes to specify when optional values should be implicit) or even a simple declarative macro. If you're adding an attribute to support this anyway, it doesn't seem like there's that much gained over just adding a macro for making builder structs.\n\nI'll admit one disadvantage of the macro-generated builder approach is that it plays somewhat less nicely with LSPs, but I think it's probably better overall in most cases.",
"title": "Way to make a configuration struct stable across versions?"
}