Optional fields in {} constructors

⚓ Rust    📅 2025-08-08    👤 surdeus    👁️ 5      

surdeus

In the last days, I tried to update my Bevy chess GUI from Bevy 0.14 to 0.16, and so I had to study a few of the recent Bevy examples codes. One is Text which has the code segment below. I wonder if there is really no more compact method available for the optional font field?

if cfg!(feature = "default_font") {
    (
        TextFont {
            font_size: 33.0,
            // If no font is specified, the default font (a minimal subset of FiraMono) will be used.
            ..default()
        },
        TextColor(GOLD.into()),
    )
} else {
    (
        // "default_font" feature is unavailable, load a font to use instead.
        TextFont {
            font: asset_server.load("fonts/FiraMono-Medium.ttf"),
            font_size: 33.0,
            ..Default::default()
        },
        TextColor(GOLD.into()),
    )
},

5 posts - 3 participants

Read full topic

🏷️ Rust_feed