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, VTable};
8
9pub trait EncodeVTable<V: VTable> {
10    /// Try to encode a canonical array into this encoding.
11    ///
12    /// The given `like` array is passed as a template, for example if the caller knows that
13    /// this encoding was successfully used previously for a similar array.
14    ///
15    /// If the encoding does not support the given array (e.g. [`crate::arrays::ConstantEncoding`]
16    /// was passed a non-constant array), then `None` is returned.
17    fn encode(
18        encoding: &V::Encoding,
19        canonical: &Canonical,
20        like: Option<&V::Array>,
21    ) -> VortexResult<Option<V::Array>>;
22}
23
24/// Default implementation for encodings that do not support encoding.
25impl<V: VTable> EncodeVTable<V> for NotSupported {
26    fn encode(
27        _encoding: &V::Encoding,
28        _canonical: &Canonical,
29        _like: Option<&V::Array>,
30    ) -> VortexResult<Option<V::Array>> {
31        Ok(None)
32    }
33}