Code Room
Code reviewHard
Question
Review this Rust function that pre-sizes a buffer before reading into it.
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.
Learn the concepts
use std::io::Read; fn read_n(mut r: impl Read, n: usize) -> std::io::Result<Vec<u8>> { let mut buf: Vec<u8> = Vec::with_capacity(n); unsafe { buf.set_len(n); } let got = r.read(&mut buf)?; buf.truncate(got); Ok(buf)}Run or narrate your approach, then ask the coach.