Closed
Description
Idea of keywords for better controlling variables initialization.
Samples:
mustinit - Variable that must be initialized before used.
let mut mustinit a = 1; // OK
a = 2; // OK
let mut mustinit x;
f(x); // Error: 'x' is not initialized
let mut mustinit x;
if something { x = 1; } else { x = 2; }
f(x); // OK
let mut mustinit x;
if something { x = 1; }
f(x); // Error: 'x' may not be initialized
initonce - Variable that can be initialized only once and then cannot be changed. It doesn't require the variable to be initialized.
let mut initonce a = 1; // OK
a = 2; // Error 'a' has been already initialized
let mut initonce a;
a = 1; // OK
a = 2; // Error 'a' has been already initialized
Metadata
Metadata
Assignees
Labels
No labels