Skip to main content

reifydb_core/
execution.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use std::ops::Deref;
5
6use reifydb_type::{error::Error, value::frame::frame::Frame};
7
8use crate::metric::ExecutionMetrics;
9
10/// Result of executing one or more RQL statements.
11///
12/// Metrics and frames are **always** present — even when execution fails.
13/// On failure, `error` holds the cause while `frames` contains partial output
14/// (whatever succeeded before the failure) and `metrics` holds partial telemetry.
15///
16/// Derefs to `[Frame]` so callers can index, iterate, or check `.is_empty()`
17/// directly while still accessing `.metrics` for telemetry.
18#[derive(Debug)]
19pub struct ExecutionResult {
20	pub frames: Vec<Frame>,
21	pub error: Option<Error>,
22	pub metrics: ExecutionMetrics,
23}
24
25impl ExecutionResult {
26	/// Returns `true` if the execution completed without error.
27	pub fn is_ok(&self) -> bool {
28		self.error.is_none()
29	}
30
31	/// Returns `true` if the execution failed.
32	pub fn is_err(&self) -> bool {
33		self.error.is_some()
34	}
35
36	/// Convert to a `Result`, enabling the `?` operator.
37	///
38	/// Returns `Ok(self)` when there is no error, `Err(e)` otherwise.
39	/// The `Ok` variant retains full access to frames and metrics.
40	pub fn check(self) -> Result<Self, Error> {
41		match self.error {
42			Some(e) => Err(e),
43			None => Ok(self),
44		}
45	}
46}
47
48impl Deref for ExecutionResult {
49	type Target = [Frame];
50
51	fn deref(&self) -> &[Frame] {
52		&self.frames
53	}
54}