hubcio commented on code in PR #2714:
URL: https://github.com/apache/iggy/pull/2714#discussion_r2811113109


##########
core/metadata/src/stm/mod.rs:
##########
@@ -20,76 +20,138 @@ pub mod mux;
 pub mod stream;
 pub mod user;
 
+use iggy_common::IggyTimestamp;
 use left_right::*;
-use std::cell::UnsafeCell;
+use std::cell::{Cell, UnsafeCell};
 use std::sync::Arc;
 
-pub struct WriteCell<T, O>
+/// Per-command handler for a given state type.
+/// Each command struct implements this for the state it mutates.
+///
+/// `now` is captured once before the command enters `left_right`, ensuring
+/// both copies see the same timestamp (deterministic replay).
+pub trait StateHandler {
+    type State;
+    type Output;
+    fn apply(&self, state: &mut Self::State, now: IggyTimestamp) -> 
Self::Output;
+}
+
+/// Parses type-erased input into a command. Macro-generated.
+/// Returns `Ok(cmd)` if applicable, `Err(input)` to pass ownership back.
+pub trait Command {
+    type Cmd;
+    type Input;
+    type Output;
+
+    fn parse(input: Self::Input) -> Result<Self::Cmd, Self::Input>;
+}
+
+/// Public interface for state machines.
+/// Returns `Ok(output)` if applicable, `Err(input)` to pass ownership back.
+pub trait State {
+    type Output;
+    type Input;
+
+    fn apply(&self, input: Self::Input) -> Result<Self::Output, Self::Input>;

Review Comment:
   as we previously discussed, it'll stay as is



##########
core/metadata/src/stm/mod.rs:
##########
@@ -20,76 +20,138 @@ pub mod mux;
 pub mod stream;
 pub mod user;
 
+use iggy_common::IggyTimestamp;
 use left_right::*;
-use std::cell::UnsafeCell;
+use std::cell::{Cell, UnsafeCell};
 use std::sync::Arc;
 
-pub struct WriteCell<T, O>
+/// Per-command handler for a given state type.
+/// Each command struct implements this for the state it mutates.
+///
+/// `now` is captured once before the command enters `left_right`, ensuring
+/// both copies see the same timestamp (deterministic replay).
+pub trait StateHandler {
+    type State;
+    type Output;
+    fn apply(&self, state: &mut Self::State, now: IggyTimestamp) -> 
Self::Output;
+}
+
+/// Parses type-erased input into a command. Macro-generated.
+/// Returns `Ok(cmd)` if applicable, `Err(input)` to pass ownership back.
+pub trait Command {
+    type Cmd;
+    type Input;
+    type Output;
+
+    fn parse(input: Self::Input) -> Result<Self::Cmd, Self::Input>;
+}
+
+/// Public interface for state machines.
+/// Returns `Ok(output)` if applicable, `Err(input)` to pass ownership back.
+pub trait State {
+    type Output;

Review Comment:
   as we previously discussed, it'll stay as is



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to