Skip to main content

vortex_array/scalar_fn/
options.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::any::Any;
5use std::fmt::Debug;
6use std::fmt::Display;
7use std::hash::Hash;
8use std::hash::Hasher;
9
10use vortex_error::VortexResult;
11
12use crate::scalar_fn::typed::DynScalarFn;
13
14/// An opaque handle to expression options.
15pub struct ScalarFnOptions<'a> {
16    pub(crate) inner: &'a dyn DynScalarFn,
17}
18
19impl Display for ScalarFnOptions<'_> {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        self.inner.options_display(f)
22    }
23}
24
25impl Debug for ScalarFnOptions<'_> {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        self.inner.options_debug(f)
28    }
29}
30
31impl PartialEq for ScalarFnOptions<'_> {
32    fn eq(&self, other: &Self) -> bool {
33        self.inner.id() == other.inner.id() && self.inner.options_eq(other.inner.options_any())
34    }
35}
36impl Eq for ScalarFnOptions<'_> {}
37
38impl Hash for ScalarFnOptions<'_> {
39    fn hash<H: Hasher>(&self, state: &mut H) {
40        self.inner.id().hash(state);
41        self.inner.options_hash(state);
42    }
43}
44
45impl ScalarFnOptions<'_> {
46    /// Serialize the options to a byte vector.
47    pub fn serialize(&self) -> VortexResult<Option<Vec<u8>>> {
48        self.inner.options_serialize()
49    }
50}
51
52impl<'a> ScalarFnOptions<'a> {
53    /// Return the underlying `Any` reference.
54    pub fn as_any(&self) -> &'a dyn Any {
55        self.inner.options_any()
56    }
57}