Code RoomConfig retries field uninitialized
HardPrep Room Coding #2014

Config retries field uninitialized

Code reviewCode quality & reviewSenior–Staff~28 min

Review this Rust code building a fixed config struct via MaybeUninit to skip a Default.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 28 min
Mark a line and say what kind of problem it is.0 findings
1use std::mem::MaybeUninit;
2struct Config { host: String, port: u16, retries: u32 }
3 
4fn build(host: String, port: u16) -> Config {
5 let mut c = MaybeUninit::<Config>::uninit();
6 let p = c.as_mut_ptr();
7 unsafe {
8 (*p).host = host; // (1)
9 (*p).port = port;
10 c.assume_init() // retries never set
11 }
12}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.