vortex_array/compute/unary/
cast.rsuse vortex_dtype::DType;
use vortex_error::{vortex_err, VortexResult};
use crate::{ArrayDType, ArrayData};
pub trait CastFn {
fn cast(&self, dtype: &DType) -> VortexResult<ArrayData>;
}
pub fn try_cast(array: impl AsRef<ArrayData>, dtype: &DType) -> VortexResult<ArrayData> {
let array = array.as_ref();
if array.dtype() == dtype {
return Ok(array.clone());
}
array.with_dyn(|a| {
a.cast()
.map(|f| f.cast(dtype))
.unwrap_or_else(|| Err(vortex_err!(NotImplemented: "cast", array.encoding().id())))
})
}