vortex_vector/decimal/macros.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Helper macros for working with the different variants of [`DecimalVector`] and
5//! [`DecimalVectorMut`].
6//!
7//! [`DecimalVector`]: super::DecimalVector
8//! [`DecimalVectorMut`]: super::DecimalVectorMut
9
10/// Matches on all decimal type variants of [`DecimalVector`] and executes the same code for
11/// each variant branch.
12///
13/// This macro eliminates repetitive match statements when implementing operations that need to work
14/// uniformly across all decimal type variants (`D8`, `D16`, `D32`, `D64`, `D128`, `D256`).
15///
16/// [`DecimalVector`]: super::DecimalVector
17#[macro_export]
18macro_rules! match_each_dvector {
19 ($self:expr, | $vec:ident | $body:block) => {{
20 match $self {
21 $crate::decimal::DecimalVector::D8($vec) => $body,
22 $crate::decimal::DecimalVector::D16($vec) => $body,
23 $crate::decimal::DecimalVector::D32($vec) => $body,
24 $crate::decimal::DecimalVector::D64($vec) => $body,
25 $crate::decimal::DecimalVector::D128($vec) => $body,
26 $crate::decimal::DecimalVector::D256($vec) => $body,
27 }
28 }};
29}
30
31/// Matches on all decimal type variants of [`DecimalVectorMut`] and executes the same code
32/// for each variant branch.
33///
34/// This macro eliminates repetitive match statements when implementing mutable operations that need
35/// to work uniformly across all decimal type variants (`D8`, `D16`, `D32`, `D64`, `D128`, `D256`).
36///
37/// [`DecimalVectorMut`]: super::DecimalVectorMut
38#[macro_export]
39macro_rules! match_each_dvector_mut {
40 ($self:expr, | $vec:ident | $body:block) => {{
41 match $self {
42 $crate::decimal::DecimalVectorMut::D8($vec) => $body,
43 $crate::decimal::DecimalVectorMut::D16($vec) => $body,
44 $crate::decimal::DecimalVectorMut::D32($vec) => $body,
45 $crate::decimal::DecimalVectorMut::D64($vec) => $body,
46 $crate::decimal::DecimalVectorMut::D128($vec) => $body,
47 $crate::decimal::DecimalVectorMut::D256($vec) => $body,
48 }
49 }};
50}