vortex_compute/cast/
primitive.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_dtype::DType;
5use vortex_error::VortexResult;
6use vortex_vector::Scalar;
7use vortex_vector::Vector;
8use vortex_vector::match_each_pscalar;
9use vortex_vector::match_each_pvector;
10use vortex_vector::primitive::PrimitiveScalar;
11use vortex_vector::primitive::PrimitiveVector;
12
13use crate::cast::Cast;
14
15impl Cast for PrimitiveVector {
16    type Output = Vector;
17
18    /// Dispatches to the underlying [`PVector<T>`](vortex_vector::primitive::PVector)
19    /// implementation.
20    fn cast(&self, target_dtype: &DType) -> VortexResult<Vector> {
21        match_each_pvector!(self, |v| { Cast::cast(v, target_dtype) })
22    }
23}
24
25impl Cast for PrimitiveScalar {
26    type Output = Scalar;
27
28    /// Dispatches to the underlying [`PScalar<T>`](vortex_vector::primitive::PScalar)
29    /// implementation.
30    fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar> {
31        match_each_pscalar!(self, |s| { Cast::cast(s, target_dtype) })
32    }
33}