Skip to main content

reifydb_sdk/transform/
context.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_abi::context::context::ContextFFI;
5
6use crate::operator::builder::ColumnsBuilder;
7
8/// Context passed to `FFITransform::transform`. Pinned to the call frame.
9pub struct FFITransformContext {
10	pub(crate) ctx: *mut ContextFFI,
11}
12
13impl FFITransformContext {
14	/// # Safety
15	/// `ctx` must be non-null and valid for the duration of the FFI call.
16	pub fn new(ctx: *mut ContextFFI) -> Self {
17		assert!(!ctx.is_null(), "ContextFFI pointer must not be null");
18		Self {
19			ctx,
20		}
21	}
22
23	/// Acquire a `ColumnsBuilder` for emitting output columns directly into
24	/// host-pool-owned buffers. The builder borrows this context for the
25	/// duration of the FFI call.
26	pub fn builder(&mut self) -> ColumnsBuilder<'_> {
27		ColumnsBuilder::from_raw_ctx(self.ctx)
28	}
29}