4 ms·
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
by m-ou-se 5y ago
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];
- lmkg 5y agoAre empty vectors const as well?
- masklinn 5y agoVec::new is const (since 1.39), so yes.
- oconnor663 5y agoOh wow, that's a big improvement. When did that stabilize?
- m-ou-se 5y agoIt was stabilized in 2019 by accident: https://twitter.com/m_ou_se/status/1396827152859942921 https://twitter.com/m_ou_se/status/1396827152859942921 https://github.com/rust-lang/rust/pull/79270 https://github.com/rust-lang/rust/pull/79270
- deleted 5y ago[deleted]