Currently, we have destructing declarations for let
, and we can apply mut
to each individual variable binding. Destructuring assignment is also being worked on too.
Yet, I've seen nothing for const
declarations, and the situation with const
is arguable worse, as constants can be initialized at the global scope, forcing code authors to workaround this by either leave unnecessary temporary globals around, e.g.:
const TEMPORARY_TUPLE: (u8, u8) = func(10);
const X: u8 = TEMPORARY_TUPLE.0;
const Y: u8 = TEMPORARY_TUPLE.1;
duplicating expressions:
const X: u8 = func(10).0;
const Y: u8 = func(10).1;
or possibly creating arbitrary modules to create scopes:
mod temporaries {
const TEMPORARY_TUPLE: (u8, u8) = func(10);
pub const X: u8 = TEMPORARY_TUPLE.0;
pub const Y: u8 = TEMPORARY_TUPLE.1;
}
use temporaries::{X, Y};
or maybe even other workarounds.
Has this suggestion be raised anywhere yet?
If not, I'd like to presume that this would be an objectively beneficial feature for the language. If anyone has any arguments against the introduction of this, or if it is infeasible to implement for any reason(s), I'd like to hear your feedback