vortex_array/vtable/
encode.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5
6use crate::Canonical;
7use crate::vtable::NotSupported;
8use crate::vtable::VTable;
9
10pub trait EncodeVTable<V: VTable> {
11    /// Try to encode a canonical array into this encoding.
12    ///
13    /// The given `like` array is passed as a template, for example if the caller knows that
14    /// this encoding was successfully used previously for a similar array.
15    ///
16    /// If the encoding does not support the given array (e.g. [`crate::arrays::ConstantVTable`]
17    /// was passed a non-constant array), then `None` is returned.
18    fn encode(
19        vtable: &V,
20        canonical: &Canonical,
21        like: Option<&V::Array>,
22    ) -> VortexResult<Option<V::Array>>;
23}
24
25/// Default implementation for encodings that do not support encoding.
26impl<V: VTable> EncodeVTable<V> for NotSupported {
27    fn encode(
28        _vtable: &V,
29        _canonical: &Canonical,
30        _like: Option<&V::Array>,
31    ) -> VortexResult<Option<V::Array>> {
32        Ok(None)
33    }
34}