macro_rules! destructure {
(let $S:path { $($field_spec:tt)* } = $value:expr) => { ... };
(let ($($var:pat_param),* $(,)?) = $value:expr) => { ... };
}Expand description
Allows destructuring in const contexts.
ยงExamples
Destructuring tuples:
use const_tools::destructure;
const fn swap<A, B>(value: (A, B)) -> (B, A) {
destructure!(let (a, b) = value);
(b, a)
}Destructuring structs:
use const_tools::destructure;
struct Pair<A, B> {
first: A,
second: B,
}
impl<A, B> Pair<A, B> {
const fn swap(self) -> Pair<B, A> {
destructure!(let Self { first, second } = self);
Pair { first: second, second: first }
}
}