Cast

Trait Cast 

Source
pub trait Cast {
    type Output;

    // Required method
    fn cast(&self, target_dtype: &DType) -> VortexResult<Self::Output>;
}
Expand description

Trait for casting vectors and scalars to different data types.

§Nullability Requirements

Casting a source that contains null values to a non-nullable target dtype will return an error. This invariant is not checked by the common helper functions, so each implementation is responsible for enforcing it.

§Common Casting Behaviors

All implementations share these behaviors:

  • Identity: Casting to the same dtype (with compatible nullability) returns a clone.
  • Null casting: Any all-null vector can be cast to DType::Null, and any null scalar can be cast to a NullScalar.
  • Extension types: Casting to an extension type delegates to casting to its storage dtype.

Required Associated Types§

Source

type Output

The output type after casting.

Required Methods§

Source

fn cast(&self, target_dtype: &DType) -> VortexResult<Self::Output>

Cast the vector or scalar to the specified data type.

Implementations on Foreign Types§

Source§

impl Cast for Datum

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Datum>

Dispatches to the contained Scalar or Vector cast implementation.

Source§

type Output = Datum

Source§

impl Cast for DecimalScalar

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Dispatches to the underlying DScalar<D> implementation.

Source§

type Output = Scalar

Source§

impl Cast for DecimalVector

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Dispatches to the underlying DVector<D> implementation.

Source§

type Output = Vector

Source§

impl Cast for PrimitiveScalar

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Dispatches to the underlying PScalar<T> implementation.

Source§

type Output = Scalar

Source§

impl Cast for PrimitiveVector

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Dispatches to the underlying PVector<T> implementation.

Source§

type Output = Vector

Source§

impl Cast for Scalar

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Dispatches to the underlying typed scalar implementation.

Source§

type Output = Scalar

Source§

impl Cast for Vector

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Dispatches to the underlying typed vector implementation.

Source§

type Output = Vector

Source§

impl Cast for BoolScalar

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Casts to Bool (identity) or Primitive (as 0/1).

Source§

type Output = Scalar

Source§

impl Cast for BoolVector

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Casts to Bool (identity) or Primitive (as 0/1).

Source§

type Output = Vector

Source§

impl Cast for FixedSizeListScalar

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Casts to FixedSizeList (identity with same element dtype, size, and compatible nullability).

Source§

type Output = Scalar

Source§

impl Cast for FixedSizeListVector

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Casts to FixedSizeList (identity with same element dtype, size, and compatible nullability).

Source§

type Output = Vector

Source§

impl Cast for ListViewScalar

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Casts to List (identity with same element dtype and compatible nullability).

Source§

type Output = Scalar

Source§

impl Cast for ListViewVector

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Casts to List (identity with same element dtype and compatible nullability).

Source§

type Output = Vector

Source§

impl Cast for NullScalar

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Casts to any nullable target type by creating a null scalar.

Source§

type Output = Scalar

Source§

impl Cast for NullVector

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Casts to any nullable target type by creating an all-null vector.

Source§

type Output = Vector

Source§

impl Cast for StructScalar

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Casts to Struct (identity with same fields and compatible nullability).

Source§

type Output = Scalar

Source§

impl Cast for StructVector

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Casts to Struct (identity with same fields and compatible nullability).

Source§

type Output = Vector

Source§

impl<D: NativeDecimalType> Cast for DVector<D>

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Casts to Decimal with potentially different precision and native type.

Source§

type Output = Vector

Source§

impl<D: NativeDecimalType> Cast for DScalar<D>

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Casts to Decimal (identity with same precision/scale and compatible nullability).

Source§

type Output = Scalar

Source§

impl<T: NativePType> Cast for PVector<T>

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Cast a primitive vector to a different primitive type.

Source§

type Output = Vector

Source§

impl<T: NativePType> Cast for PScalar<T>

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Cast a primitive scalar to a different primitive type.

Source§

type Output = Scalar

Source§

impl<T: BinaryViewType> Cast for BinaryViewScalar<T>

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar>

Casts to Utf8 or Binary (identity cast with compatible nullability).

Source§

type Output = Scalar

Source§

impl<T: BinaryViewType> Cast for BinaryViewVector<T>

Source§

fn cast(&self, target_dtype: &DType) -> VortexResult<Vector>

Casts to Utf8 or Binary (identity cast with compatible nullability).

Source§

type Output = Vector

Implementors§