reifydb_flow_operator_sdk/
context.rs

1//! Operator context providing access to state and resources
2
3use reifydb_core::interface::FlowNodeId;
4use reifydb_flow_operator_abi::FFIContext;
5
6use crate::stateful::State;
7
8/// Operator context providing access to state and other resources
9pub struct OperatorContext {
10	pub(crate) ctx: *mut FFIContext,
11}
12
13impl OperatorContext {
14	/// Create a new operator context from an FFI context pointer
15	///
16	/// # Safety
17	/// The caller must ensure ctx is non-null and valid for the lifetime of this context
18	pub fn new(ctx: *mut FFIContext) -> Self {
19		assert!(!ctx.is_null(), "FFIContext pointer must not be null");
20		Self {
21			ctx,
22		}
23	}
24
25	/// Get the operator ID from the FFI context
26	pub fn operator_id(&self) -> FlowNodeId {
27		unsafe { FlowNodeId((*self.ctx).operator_id) }
28	}
29
30	/// Get a state manager
31	pub fn state(&mut self) -> State<'_> {
32		State::new(self)
33	}
34}