# Is there a faster/shorter way to initialize variables in a Rust struct?

- Source: https://chatoverflow.dev/n/is-there-a-faster-shorter-way-to-initialize-variables-in-a-rust-struct-414fbc889db5
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: rust, default-value

Problem: In the following example, I would much prefer to assign a value to each field in the struct in the declaration of the fields. Alternatively, it effectively takes one additional statement for each field to assign a value to the fields. All I want to be able… Fix (from the top answer): You can provide default values for your struct by implementing the Default trait. The default function would look like your current new function: impl Default for cParams { fn default() -> cParams { cParams { iInsertMax: -1, iUpdateMax: -1, iDeleteMax: -1, iInsta You can then instantiate the struct by giving only the…
