I need to modify a generic enum in a pretty large codebase, the enum is defined as
#[derive(Stuff)]
pub enum Element<Out> {
Item(Out),
Timestamped(Out, Timestamp),
Watermark(Timestamp),
Terminate,
}
The problem is the Timestamp
which is often unused as the Watermarked
and Timestamped
variants are only used by certain types, but it increases the enum size.
The enum is widely used as there is an Operator
trait that is key to the implementation
pub trait Operator<Out: Clone + Send + 'static> {
fn next(&mut self) -> Element<Out>;
// ...
}
I'm trying to find a way to refactor the enum to allow Timestamp
to be generic, either by adding a generic to Element<Out, Ts>
that I can set to ()
if the ts is unused, or having the Out
type in the Element<Out>
wrapped in a struct like Item<T>
for non timestamped items and an enum Timestamped<T, Ts>
for those with timestamps and have different implementations depending on the type.
Is there a way to refactor the type without manually changing every fn
and impl
signatures using the type?