News for hackers. Stuff that matters.
Re:Methods for Array Initialization in Rust (2018) by m-ou-se on Monday May 24, 2021 @09:32AM (#27264140)
An important one is missing from this overview: using a const. This is sometimes useful, because it does not require the type to be Copy; only that the value is a constant:

    const EMPTY: String = String::new();
    let a: [String; 1000] = [EMPTY; 1000];

    const NONE: Option<String> = None;
    let b: [Option<String>; 1000] = [NONE; 1000];

    const SEVEN: AtomicU32 = AtomicU32::new(7);
    let c: [AtomicU32; 200] = [SEVEN; 200];
Re:Methods for Array Initialization in Rust (2018) by oconnor663 on Monday May 24, 2021 @10:29AM (#27264754)
Oh wow, that's a big improvement. When did that stabilize?
Re:Methods for Array Initialization in Rust (2018) by m-ou-se on Monday May 24, 2021 @10:32AM (#27264790)
Re:Methods for Array Initialization in Rust (2018) by lmkg on Monday May 24, 2021 @09:52AM (#27264366)
Are empty vectors const as well?
Re:Methods for Array Initialization in Rust (2018) by masklinn on Monday May 24, 2021 @09:59AM (#27264426)
Vec::new is const (since 1.39), so yes.