Refactor PushableSeries trait

Introduce a new trait `PushableSeries` to distinguish objects that can
have values pushed into them from those that are only readable series.
This clarifies the API and allows for more precise type checking.

The `Object` trait no longer has a default `push_value` implementation.
Instead, `PushableSeries` now provides this functionality.
`SeriesMember` has also been updated to require `PushableSeries` for
RecordSeries field buffers.
This commit is contained in:
2026-03-22 19:45:50 +01:00
parent 843ee7dfed
commit ae1d94e507
2 changed files with 50 additions and 25 deletions
+13 -9
View File
@@ -176,7 +176,7 @@ impl RecordLayout {
}
}
/// Interface for custom objects (Closures, Series, Streams)
/// Interface for custom objects (Series, Streams, SyntaxNodes, and custom extensions).
pub trait Object: fmt::Debug {
fn type_name(&self) -> &'static str;
fn as_any(&self) -> &dyn Any;
@@ -185,17 +185,21 @@ pub trait Object: fmt::Debug {
/// `Rc<T>` via `Rc::downcast::<T>()`. Requires `arbitrary_self_types` (stable since 1.81).
fn into_rc_any(self: Rc<Self>) -> Rc<dyn Any>;
/// Pushes a value into this object if it is a mutable series.
/// The default implementation panics — only series types override this.
fn push_value(&self, _val: Value) {
panic!("{} does not support push_value", self.type_name());
}
/// Optional optimization: If this object behaves like a time series (indexable lookbacks),
/// it can return a reference to its Series trait implementation.
/// If this object supports indexed lookback access, returns a `Series` reference.
fn as_series(&self) -> Option<&dyn Series> {
None
}
/// If this object supports pushing new values, returns a `PushableSeries` reference.
fn as_pushable_series(&self) -> Option<&dyn PushableSeries> {
None
}
}
/// Extension of `Object + Series` for types that also accept new values via `push_value`.
/// Only series types that are mutable (ScalarSeries, ValueSeries, RecordSeries) implement this.
pub trait PushableSeries: Object + Series {
fn push_value(&self, val: Value);
}
/// Unified interface for all series types (Local RecordSeries, SeriesViews, and future SharedSeries).