|
4 | 4 | //! Typed and inner representations of scalar functions. |
5 | 5 | //! |
6 | 6 | //! - [`ScalarFn<V>`]: The public typed wrapper, parameterized by a concrete [`ScalarFnVTable`]. |
7 | | -//! - [`ScalarFnInner<V>`]: The private inner struct that holds the vtable + options. |
| 7 | +//! - [`ScalarFn<V>`]: The private inner struct that holds the vtable + options. |
8 | 8 | //! - [`DynScalarFn`]: The private sealed trait for type-erased dispatch (bound, options in self). |
9 | 9 |
|
10 | 10 | use std::any::Any; |
@@ -35,9 +35,43 @@ use crate::scalar_fn::ScalarFnRef; |
35 | 35 | use crate::scalar_fn::ScalarFnVTable; |
36 | 36 | use crate::scalar_fn::SimplifyCtx; |
37 | 37 |
|
| 38 | +/// A typed scalar function instance, parameterized by a concrete [`ScalarFnVTable`]. |
| 39 | +/// |
| 40 | +/// You can construct one via [`new()`], and erase the type with [`erased()`] to obtain a |
| 41 | +/// [`ScalarFnRef`]. |
| 42 | +/// |
| 43 | +/// [`new()`]: ScalarFn::new |
| 44 | +/// [`erased()`]: ScalarFn::erased |
| 45 | +pub struct ScalarFn<V: ScalarFnVTable> { |
| 46 | + vtable: V, |
| 47 | + options: V::Options, |
| 48 | +} |
| 49 | + |
| 50 | +impl<V: ScalarFnVTable> ScalarFn<V> { |
| 51 | + /// Create a new typed scalar function instance. |
| 52 | + pub fn new(vtable: V, options: V::Options) -> Self { |
| 53 | + Self { vtable, options } |
| 54 | + } |
| 55 | + |
| 56 | + /// Returns a reference to the vtable. |
| 57 | + pub fn vtable(&self) -> &V { |
| 58 | + &self.vtable |
| 59 | + } |
| 60 | + |
| 61 | + /// Returns a reference to the options. |
| 62 | + pub fn options(&self) -> &V::Options { |
| 63 | + &self.options |
| 64 | + } |
| 65 | + |
| 66 | + /// Erase the concrete type information, returning a type-erased [`ScalarFnRef`]. |
| 67 | + pub fn erased(self) -> ScalarFnRef { |
| 68 | + ScalarFnRef(Arc::new(self)) |
| 69 | + } |
| 70 | +} |
| 71 | + |
38 | 72 | /// An object-safe, sealed trait for bound scalar function dispatch. |
39 | 73 | /// |
40 | | -/// Options are stored inside the implementing [`ScalarFnInner<V>`], not passed externally. |
| 74 | +/// Options are stored inside the implementing [`ScalarFn<V>`], not passed externally. |
41 | 75 | /// This is the sole trait behind [`ScalarFnRef`]'s `Arc<dyn DynScalarFn>`. |
42 | 76 | pub(super) trait DynScalarFn: 'static + Send + Sync + super::sealed::Sealed { |
43 | 77 | fn as_any(&self) -> &dyn Any; |
@@ -86,16 +120,7 @@ pub(super) trait DynScalarFn: 'static + Send + Sync + super::sealed::Sealed { |
86 | 120 | fn options_debug(&self, f: &mut Formatter<'_>) -> fmt::Result; |
87 | 121 | } |
88 | 122 |
|
89 | | -/// The private inner representation of a bound scalar function, pairing a vtable with its options. |
90 | | -/// |
91 | | -/// This is the sole implementor of [`DynScalarFn`], enabling [`ScalarFnRef`] to safely downcast |
92 | | -/// back to the concrete vtable type via [`Any`]. |
93 | | -pub(super) struct ScalarFnInner<V: ScalarFnVTable> { |
94 | | - pub(super) vtable: V, |
95 | | - pub(super) options: V::Options, |
96 | | -} |
97 | | - |
98 | | -impl<V: ScalarFnVTable> DynScalarFn for ScalarFnInner<V> { |
| 123 | +impl<V: ScalarFnVTable> DynScalarFn for ScalarFn<V> { |
99 | 124 | #[inline(always)] |
100 | 125 | fn as_any(&self) -> &dyn Any { |
101 | 126 | self |
@@ -232,34 +257,3 @@ impl<V: ScalarFnVTable> DynScalarFn for ScalarFnInner<V> { |
232 | 257 | Debug::fmt(&self.options, f) |
233 | 258 | } |
234 | 259 | } |
235 | | - |
236 | | -/// A typed scalar function instance, parameterized by a concrete [`ScalarFnVTable`]. |
237 | | -/// |
238 | | -/// You can construct one via [`new()`], and erase the type with [`erased()`] to obtain a |
239 | | -/// [`ScalarFnRef`]. |
240 | | -/// |
241 | | -/// [`new()`]: ScalarFn::new |
242 | | -/// [`erased()`]: ScalarFn::erased |
243 | | -pub struct ScalarFn<V: ScalarFnVTable>(pub(super) Arc<ScalarFnInner<V>>); |
244 | | - |
245 | | -impl<V: ScalarFnVTable> ScalarFn<V> { |
246 | | - /// Create a new typed scalar function instance. |
247 | | - pub fn new(vtable: V, options: V::Options) -> Self { |
248 | | - Self(Arc::new(ScalarFnInner { vtable, options })) |
249 | | - } |
250 | | - |
251 | | - /// Returns a reference to the vtable. |
252 | | - pub fn vtable(&self) -> &V { |
253 | | - &self.0.vtable |
254 | | - } |
255 | | - |
256 | | - /// Returns a reference to the options. |
257 | | - pub fn options(&self) -> &V::Options { |
258 | | - &self.0.options |
259 | | - } |
260 | | - |
261 | | - /// Erase the concrete type information, returning a type-erased [`ScalarFnRef`]. |
262 | | - pub fn erased(self) -> ScalarFnRef { |
263 | | - ScalarFnRef(self.0) |
264 | | - } |
265 | | -} |
0 commit comments