risingwave_common

Macro for_all_variants

source
macro_rules! for_all_variants {
    ($macro:ident $(, $x:tt)*) => { ... };
}
Expand description

for_all_variants includes all variants of our type system. If you introduced a new array type (also known as scalar type or physical type), be sure to add a variant here.

It is used to simplify the boilerplate code of repeating all array types, while each type has exactly the same code.

Take Utf8 as an example, the layout of the variant is:

  • $data_type: Varchar data type variant name, e.g. DataType::Varchar
  • $variant_name: Utf8 array type variant name, e.g. ArrayImpl::Utf8, ScalarImpl::Utf8
  • $suffix_name: utf8 the suffix of some functions, e.g. ArrayImpl::as_utf8
  • $scalar: Box<str> the scalar type, e.g. ScalarImpl::Utf8(Box<str>)
  • $scalar_ref: &'scalar str the scalar reference type, e.g. ScalarRefImpl::Utf8(&'scalar str)
  • $array: Utf8Array the array type, e.g. ArrayImpl::Utf8(Utf8Array)
  • $builder: Utf8ArrayBuilder the array builder type, e.g. ArrayBuilderImpl::Utf8(Utf8ArrayBuilder)

To use it, one need to provide another macro which accepts arguments in the layout described above. Refer to the following implementations as examples.

Note: See also dispatch_xx_variants and dispatch_data_types which doesn’t require another macro for the implementation and can be easier to use in most cases.