vortex_array/vtable/
encode.rs

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