Skip to main content

vortex_array/
matcher.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use crate::ArrayRef;
5
6/// Trait for matching array types.
7pub trait Matcher {
8    type Match<'a>;
9
10    /// Check if the given array matches this matcher type
11    #[inline]
12    fn matches(array: &ArrayRef) -> bool {
13        Self::try_match(array).is_some()
14    }
15
16    /// Try to match the given array, returning the matched view type if successful.
17    fn try_match(array: &ArrayRef) -> Option<Self::Match<'_>>;
18}
19
20/// Matches any array type (wildcard matcher)
21#[derive(Debug)]
22pub struct AnyArray;
23
24impl Matcher for AnyArray {
25    type Match<'a> = &'a ArrayRef;
26
27    #[inline(always)]
28    fn matches(_array: &ArrayRef) -> bool {
29        true
30    }
31
32    #[inline(always)]
33    fn try_match(array: &ArrayRef) -> Option<Self::Match<'_>> {
34        Some(array)
35    }
36}